y-a-v-a / node-gd

🎨 GD graphics library (libgd) C++ bindings for Node.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how i can resize image with node GD

arslbbt opened this issue · comments

commented

how i can resize image with node GD

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

commented

ok please send me asap

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