Page 1 of 1

Error Converting PNG File

Posted: 2013-06-28T20:39:17-07:00
by pgill
Hi,

I am using imagemagick in nodejs and I get this error when trying to resize and convert a PNG image to a JPG image using imagemagick-6.8.0-10 on my Mac v10.8.3:
Error: Command failed: convert: Expected 8192 bytes; found 7058 bytes `/var/tmp/magick-5575V2-7DKZLYZj1' @ warning/png.c/MagickPNGWarningHandler/1830.
convert: Read Exception `/var/tmp/magick-5575V2-7DKZLYZj1' @ error/png.c/MagickPNGErrorHandler/1804.
convert: corrupt image `/var/tmp/magick-5575V2-7DKZLYZj1' @ error/png.c/ReadPNGImage/4048.
convert: no images defined `/tmp/51cd11dbc2f44e2469b1619b_1372476626911.jpg' @ error/convert.c/ConvertImageCommand/3106.

Here is some sample code:

Code: Select all

 // Download any PNG file
        var source_image = "http://example.com/some_file.png";
        var request = request_module.get(source_image, function(res) {
          var imagedata = '';
          res.setEncoding('binary');
          res.on('data', function(chunk){
            imagedata += chunk;
          });
          res.on('end', function() {            
             imagemagick.resize({
                srcData: image_data,
                dstPath: tmp_filename,
                width: 1000,
                quality: 0.8,
                format: 'jpg'
              }, 
          });
Any ideas on what could be wrong? Thanks!

Re: Error Converting PNG File

Posted: 2013-06-29T06:15:47-07:00
by glennrp
Are you seeing the error with all PNG files or with one particular file? If it's just the one file then it may be truncated. If it's all PNG files, then maybe your temporary directory got filled and the working file became truncated.

Re: Error Converting PNG File

Posted: 2013-06-29T12:57:38-07:00
by pgill
Thanks for your response!

I am seeing it with all PNG files. Checked the tmp directory and deleted pretty much everything in there with no luck.

EDIT: I then tried to write the image data to a file and pass in the file path to imagemagick, and that works.

So there seems to be an issue with passing in the image as srcData. Passing in the srcPath works.

Looking at the imagemagick code, I couldn't tell if imagemagick creates a temporary file when passed in srcData. If that is the case, then I don't mind getting around this by just passing in srcPath.

From the looks of it, it tried to read from: /var/tmp/magick-5575V2-7DKZLYZj1 which to me implies that passing in srcData creates a tmp file. However, when I go to that directory, I don't see that file at all.

Any insight here would be much appreciated.

Thanks!