title: Missing image filename ImageMagick convert running from Node.js only
body: <p>I built a little script that will first montage 8 tiles together, then scale it down and then it has to distort the image.</p>
  
  <p>Everything goes according to plan until the distorting part.</p>
  
  <pre><code>this.distort = function(filename) {
    var distortDeferred = Q.defer();
  
    var totalWidth = width * waves * 2,
        totalHeight = height * waves * 2;
  
    var params = [
      filename,
      '-matte',
      '-virtual-pixel',
      'transparent',
      '-distort',
      'Perspective "{left},{top} {newLeft},{top}   {left},{bottom} {left},{bottom}   {right},{bottom} {right},{bottom}    {right},{top} {newRight},{top}"'.assign({
        left: 0,
        top: 0,
        newLeft: totalWidth * distortPercentage,
        bottom: totalHeight,
        right: totalWidth,
        newRight: totalWidth - totalWidth * distortPercentage
      }),
      filename
    ];
  
    im.convert(params, function() {
      console.log(arguments);
    });
  
    return distortDeferred.promise;
  };
  </code></pre>
  
  <p>This following function wil give the error:</p>
  
  <pre><code>Error: Command failed: convert: missing an image filename `tmp/5458f2e3d6840bb65ba6100f.png' @ error/convert.c/ConvertImageCommand/3184.
  </code></pre>
  
  <p>Running the exact same operation on the command line, will have the desired output.</p>
  
  <p>Possible mistakes I could have made and that I have tested:</p>
  
  <ul>
  <li>Two image converts, converting the image at the same time</li>
  <li>Non existing image</li>
  <li>File rights to the image are not set correctly</li>
  <li>Missing plugins for ImageMagick</li>
  </ul>
  
  <p><strong>Two image converts, converting the image at the same time</strong></p>
  
  <p>Everything is done with deferreds and promises, so it's not possible that two requests run at the same time, to be sure I set a 2000ms timeout before the distort function was called. Also no help.</p>
  
  <p><strong>Non existing image</strong></p>
  
  <p>Tested this to be sure with a <code>fs.fileExists</code>. Result was as expected.</p>
  
  <p><strong>File rights to the image are not set correctly</strong></p>
  
  <p>To be safe I tried a <code>chmod -R 777 folder</code> on the folder. Result was as expected.</p>
  
  <p><strong>Missing plugins for ImageMagick</strong></p>
  
  <p>After some googling I came across some people that didn't have the appropriate plugins installed and received the same error as me.</p>
  
  <p>Apparently it had something to with either a JPEG library missing or a PNG, <a href="https://stackoverflow.com/questions/8488695/imagemagick-not-converting">see error here</a>.</p>
  
  <p>So after running <code>identify -list format</code>, it was apparent that I have the appropriate libraries installed to complete an operation like this.</p>
  
  <p><strong>Synopsis</strong></p>
  
  <p>I think the error is also probably found in node instead of ImageMagick, because the operation runs from the command line without a problem.</p>