我的代码是否适用于localhost,但不适用于EC2(我使用的是Elastic BeanStalk)。我收到错误:流在 toBuffer 函数上产生空缓冲区。有人可以解释一下如何解决它吗?我看到了这个post,但我不明白如何在EC2中添加JPEG支持。
var _45px = { width: 45, dstnKey: fileName, destinationPath: "thumbnails" };
function convert(response, next) {
console.time("convertImage");
console.log("Reponse content type : " + response.ContentType);
console.log("Conversion");
GM(response.Body, fullName).antialias(true).density(300).setFormat('jpeg').toBuffer(
function(err, buffer) {
if (err) {
next(err);
} else {
console.timeEnd("convertImage");
next(null, buffer);
}
});
}
答案 0 :(得分:-2)
我遇到了类似PNG格式的问题。问题出现是因为EC2实例不支持PNG和JPEG,因此我们需要相应地安装所需的依赖项,否则imagemagick(或graphicmagick)不会返回任何流值作为输出。
为了添加PNG支持,我尝试卸载了graphicsmagick模块,然后安装了依赖项并重新安装了graphicsmagick:
apt-get install libpng-dev, apt-get install graphicsmagick (在你的情况下,这将是imagemagick)
这解决了这个问题。我相信jpeg支持库将是: 的libjpeg-dev的。
这些适用于EC2 ubuntu实例