Resize and crop image and keeping aspect ratio NodeJS & gm

后端 未结 5 1223
囚心锁ツ
囚心锁ツ 2020-12-23 17:18

I\'ve been trying to create some thumbnails using the gm package from NodeJS, but I\'m out of lucky. I need to resize images bigger than 600x600 (could be any w

5条回答
  •  暖寄归人
    2020-12-23 17:59

    Try with imagemagick package for 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() + ' to fit within 200x200px');
    });
    

    Update: Please note that the node-imagemagick package hasn't been updated in quite a long time. Please consider Freyday's answer since it's most up-to-date.

提交回复
热议问题