1,安首先要安装 GraphicsMagick或者ImageMagick
2,npm install gm --save
3,编码测试
var fs = require('fs') //graphMagick const gm = require('gm'); //imageMagick //const gm = require('gm').subClass({imageMagick: true}); // resize and remove EXIF profile data gm('./20191012105220251.jpg') .resize() .noProfile() //清除图片信息 .quality(70) //图像质量 .autoOrient() //自动旋转 //.crop(800,200,100,100)//裁剪参数(w,h,x,y) .write('./resize.jpg', function (err) { if (!err) console.log('done'); });