Resize and crop image and keeping aspect ratio NodeJS & gm

后端 未结 5 1208
囚心锁ツ
囚心锁ツ 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:41

    Try with Jimp package for Node.js https://www.npmjs.com/package/jimp. Which is better than gm I think. It does not require any dependencies. I tried to use gm before but I was not able to install dependencies for gm. End up I used jimp and everything worked fine.

       Jimp.read('lenna.png', (err, lenna) => {
          if (err) throw err;
          lenna
            .resize(256, 256) // resize
            .write('lena-small-bw.jpg'); // save
        });
    

提交回复
热议问题