在Node中使用GraphicsMagick将PNG缓冲区转换为JPG

8

如何在不写入文件的情况下将PNG缓冲区转换为JPG?


这可能会有所帮助:https://dev59.com/9mPVa4cB1Zd3GeqP3jjY - user2319961
不要以为你可以在不写入文件的情况下完成它... - user2319961
1
使用 https://github.com/aheckmann/gm - Jonathan Ong
你能解释一下为什么无法写入文件吗?那么内存映射(瞬态)文件呢? - Delaney
1个回答

6
你可以使用https://github.com/aheckmann/gm
var gm = require('gm')

// convert a buffer to a stream
gm(buffer, 'img.png')
.stream('jpg')
.pipe(outputStream);


// convert a buffer to a buffer
gm(buffer, 'img.png')
.toBuffer('PNG',function (err, buffer) {
   if (err) return handle(err);
   console.log('done!');
})

请注意:这似乎不适用于最新版本的GraphicsMagick。 - yeah22

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接