Search code examples
javascriptnode.jsimagemagickspawn

NodeJs, Spawn convert


I want to execute convert inside Node using spawn.
this command runs without any error :

var args = [
  'img1.jpg',
  'img2.jpg',
  '-gravity', 'center',
  '-composite', '-'
];

var ls = spawn('convert',args);
ls.stderr.on('data', function (data) {
   console.log('stderr: ' + data);
});

but when I try this one :

var args = [
  'img1.jpg',
  '\\( img2.jpg -resize 10x10 \\)',
  '-gravity', 'center',
  '-composite', '-'
];
var ls = spawn('convert',args);
ls.stderr.on('data', function (data) {
   console.log('stderr: ' + data);
});

getting this Error:

stderr: convert: unable to open image `\( img2.jpg -resize 10x10 \)': No such file or directory @ error/blob.c/OpenBlob/2702.
convert: no decode delegate for this image format `JPG -RESIZE 10X10 \)' @ error/constitute.c/ReadImage/504.
convert: no images defined `-' @ error/convert.c/ConvertImageCommand/3257.

Solution

  • I found the Answer: arguments must be splitted all:

    var args = [
      'img1.jpg',
      '\\(','img2.jpg','-resize','10x10','\\)',
      '-gravity', 'center',
      '-composite', '-'
    ];