且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Google Cloud Storage上将PDF转换为PNG

更新时间:2023-11-11 21:12:28

我刚刚意识到gm可以处理ImageMagick,而您已经做到了(使用.subClass({imageMagick: true})),那么为什么还要麻烦另一个包装器呢?

I just realized gm can handle ImageMagick, and you already do it (using .subClass({imageMagick: true})), so why bother with another wrapper?

无论如何,我只是尝试了这一点:

Anyway, I just tried this:

const gm = require('gm').subClass({imageMagick: true});
const file = './test.pdf';
gm(file)
.resize(250, 250)
.setFormat('png')
.write(file, (err) => {
    if (err) console.log('FAILED', err);
    else console.log('SUCCESS');
});

它指出了一些未授权"错误,因为最初禁用了PDF处理-请参见-但在我完成之后根据建议编辑了/etc/ImageMagick*/policy.xml,效果很好.

It stated some "not authorized" error because PDF processing is originally disabled - see this - but after I've edited /etc/ImageMagick*/policy.xml as suggested, it worked perfectly.