How do I convert a png buffer to a jpg without writing to a file?
Asked
Active
Viewed 9,071 times
8
-
this might help http://stackoverflow.com/questions/10359214/graphicsmagick-for-node-not-writing-the-whole-jpg – May 20 '13 at 14:49
-
don't think you can do it without writing to a file... – May 20 '13 at 14:51
-
1use https://github.com/aheckmann/gm – Jonathan Ong Sep 26 '13 at 08:49
-
Can you clarify why you can't write to a file? What about a memory-mapped (transient) file? – Delaney Aug 27 '14 at 14:36
1 Answers
6
You can use 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!');
})

smremde
- 1,800
- 1
- 13
- 25
-
note: this doesn't seem to work with the latest version of graphicsmagick – yeah22 Feb 05 '22 at 22:56