Error Converting PNG File

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
pgill
Posts: 2
Joined: 2013-06-28T20:27:33-07:00
Authentication code: 6789

Error Converting PNG File

Post 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!
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Error Converting PNG File

Post 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.
pgill
Posts: 2
Joined: 2013-06-28T20:27:33-07:00
Authentication code: 6789

Re: Error Converting PNG File

Post 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!
Post Reply