how i can resize image with node GD
arslbbt opened this issue · comments
AR commented
how i can resize image with node GD
Vincent Bruijn commented
Hi @arslbbt, thanks for reaching out!
The best way to resize an image with node GD is to copy the source image upon a target image. I will paste example code in a few minutes here.
Cheers Vincent
AR commented
ok please send me asap
Vincent Bruijn commented
Hi @arslbbt well you should be happy that I'm available. This is an issue tracker and not a help desk. Feel free to take a look at the rather extensive documentation which covers a lot of topics: https://y-a-v-a.github.io/node-gd/
That being said, here's some example code.
const gd = require('node-gd');
// open the source image
gd.openJpeg('./fixtures/input.jpg', (error, img) => {
if (error) {
throw error;
}
// create a new target file in memory of 1400x1400 px
let newImg = gd.createTrueColorSync(1400,1400);
// copy the source image onto newImg
img.copyResized(newImg, 0, 0, 0, 0, 1400, 1400, img.width, img.height);
// save the target image
newImg.saveJpeg('/tmp/large.jpg', 100, (error) => {
if (error) {
throw error;
}
});
});
Next time, don't expect me te respond that quickly, you're lucky.
Regards, Vincent