GraphicsMagick:toBuffer()流产生空缓冲区 [英] GraphicsMagick: toBuffer() Stream yields empty buffer

查看:222
本文介绍了GraphicsMagick:toBuffer()流产生空缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下示例代码将文件读入缓冲区,调整大小,然后将其写入磁盘:

I am trying to read a file into a buffer, resize it and then write it to disk using the following example code:

function processImage(data) {
gm(data, 'test.jpg')
    .resize('300x300')
  .background('white')
  .flatten()
  .setFormat('jpg')
  .toBuffer(function(err, buffer) {
    if (err) {
        throw err;
    } else {
        fs.writeFile('asd.jpg', buffer);
    }
  });
}

但是,这会生成错误Error: Stream yields empty buffer.我玩过,使用imageMagick和graphicsMagick,仍然一样.

However, this generates an error Error: Stream yields empty buffer. I have played around, used imageMagick and graphicsMagick, still the same.

如果我替代
toBuffer(...

write('asd.jpg', function(err) ...

If i substitute
toBuffer(...
with
write('asd.jpg', function(err) ...

它实际上写入了正确的文件.

it actually writes a proper file.

编辑在写此问题时,我找到了解决方法,请参见答复

EDIT While writing this question I found the solution, see reply

推荐答案

setFormat('jpg')
造成了问题.将其更改为
setFormat('jpeg')解决了.

setFormat('jpg')
caused the problems. Changing it to
setFormat('jpeg') solved it.

这篇关于GraphicsMagick:toBuffer()流产生空缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆