node.js - Resize and crop image and keeping aspect ratio NodeJS & gm -
i've been trying create thumbnails using gm
package nodejs, i'm out of lucky. need resize images bigger 600x600 (could width/height, starting given one) when pass size gm, creates image doesn't have same size requested.
for example, given code, assume running node app /path/to/image.png
i'll receive image size of 200x100, instead got, say, image of 180x100 or 200x90...
gm(filelocation) .thumb(200, 100, 'processed.' + process.argv[2].split('.').pop(), function() { console.log("done!"); });
i've tried resize option. there's option force size, aspect ratio of output goes horrible...
gm('/path/to/image.jpg') .resize(353, 257) .write(writestream, function (err) { if (!err) console.log(' hooray! '); });
try imagemagick
package nodejs: https://github.com/yourdeveloper/node-imagemagick
im.crop({ srcpath: process.argv[2], dstpath: 'cropped.' + process.argv[2].split('.').pop(), width: 200, height: 200, quality: 1, gravity: 'center' }, function(err, stdout, stderr){ if (err) throw err; console.log('resized ' + process.argv[2].split('/').pop() + ' fit within 200x200px'); });
update: please note node-imagemagick package hasn't been updated in quite long time. please consider freyday's answer since it's up-to-date.
Comments
Post a Comment