Invalid file name image. ImageMagick converts from Node.js.

I built a small script that will first mount 8 tiles together, then scale it and then distort the image.

Everything goes according to plan until the distorting part.

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;
};

      

This next function wil gives an error:

Error: Command failed: convert: missing an image filename `tmp/5458f2e3d6840bb65ba6100f.png' @ error/convert.c/ConvertImageCommand/3184.

      

Performing the same operation on the command line will have the desired result.

Possible mistakes I could make and what I tested:

  • Two images are converted by converting the image at the same time
  • Non-existent image
  • Image rights not set correctly
  • Missing plugins for ImageMagick

Two images are converted, converting the image at the same time

Everything is done with delays and promises, so it is not possible for two requests to be executed at the same time to set the timeout to 2000ms before the mangle function was called. Also doesn't help.

Non-existent image

Tested this with fs.fileExists

. The result was as expected.

Image rights not set correctly

To be on the safe side, I tried chmod -R 777 folder

the folder. The result was as expected.

Missing plugins for ImageMagick

After some googling, I came across some people who didn't have the respective plugins installed and got the same error as me.

Apparently it had something with the missing JPEG or PNG library, here.

So after starting identify -list format

it was obvious that I had the appropriate libraries installed to perform such an operation.

Summary

I think the error is also probably found in node instead of ImageMagick because the operation is done from the command line with no problem.

+3


source to share





All Articles