node.js How to create thumbnail from image?

xfakehopex picture xfakehopex · Jul 16, 2014 · Viewed 13.6k times · Source

I'm using gm module.This is my code:

gm(picture.path).thumb('250', '180', picture.thumb_path, 100, function (error) {
   if(error) console.log(error);
});

But result size sometimes is 249x180. I need 250x180

Answer

xfakehopex picture xfakehopex · Jul 17, 2014

I have solved it with this code:

imageMagick(picture.path)
    .resize('250', '180', '^')
    .gravity('center')
    .extent(250, 180)
    .write(picture.thumb_path, function (error) {
       if(error) console.log(error);
});