How to Deal with node Picture Cutting Background Urgently

  node.js, question

Objective: To trim the uploaded pictures.

I tried to use Baidu onlinegm, how to do is not. ImageMagick is also quoted.

Problem: The picture can be generated, but the picture has no content and is blank.


var fileReadStream = fs.createReadStream(old_path);
 var fileWriteStream = fs.createWriteStream(new_path);
 .resize('200', '200')
 .stream(function(err, stdout, stderr) {

Find out where your problem is:
There is a paragraph in gm that reads as follows: I didn’t pay attention to it

First download and install GraphicsMagick or ImageMagick. In Mac OS X, you can simply use Homebrew and do:

I thought npm installed ImageMagick, but it still needs to configure environment variables. Thank you for the following answer

Coincidentally, in my project, I took nodejs as the picture server. There used to be a code with picture processing written on it. Take a look at it. I have no problem here.I added watermark and modified the size of this one.

var gm = require('gm');
 var watermark = 'logo.png';
 var spawn = require('child_process').spawn;
 function resize_image(path, max_width, callback){
 gm(path).resize(max_width, null, '>').quality(80).setFormat('JPEG').write(path, callback);
 function add_watermark(path, callback){
 var composite = spawn('gm', ['composite', '-gravity', 'SouthEast', '-dissolve', '80', 'logo.png', path, path]);
 composite.on('exit', function(code){