Reputation: 2944
How could I convert a tiff
to jpg
in node.js and GraphicsMagick gm
(https://aheckmann.github.io/gm/)?
I want to do this on AWS lambda, so cant write()
out to disk as such.
Upvotes: 0
Views: 3908
Reputation: 11
I don't know what's wrong but, with this library, it does not works for me. If I use:
https://www.npmjs.com/package/jimp
it works for me. Maybe this helps someone.
const Jimp = require('jimp');
try {
const readFile = await Jimp.read(filePath)
await readFile.writeAsync(pathToConvertedFile)
const buffPng = await fs.readFile(pathToConvertedFile);
} catch (err) {
console.log(err);
}
Upvotes: 1
Reputation: 5921
Simply specify the file extension you want to the .write()
method and gm will convert it automatically in that format.
const gm = require('gm');
gm('sample.tiff')
.write('out.jpeg', function (err) {
if (err) console.log(err);
});
If you need to output as buffer instead of writing to disk, you can use .toBuffer()
method:
gm('sample.tiff')
.toBuffer('jpeg', function (err, buffer) {
if (err) console.log(err);
});
Upvotes: 3