Search code examples
linuxcommand-lineimagick

Cropping two transparent png images using Imagick gives different results


I am having different result when cropping two png files.

Imagick Version using convert -version:

  • Version: ImageMagick 6.6.5-10 2010-11-26 Q16
  • Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
  • Features: OpenMP

The two files using identify:

  • works.png PNG 1218x610 1218x610+0+0 8-bit DirectClass 755KB 0.000u 0:00.000
  • doesntwork.png PNG 70x70 70x70+0+0 8-bit DirectClass 1.64KB 0.000u 0:00.000

I am using this command:

convert <original>.png -crop 50x50+0+0 <target>.png

The problem is that works.png is 100% correct, while doesntwork.png is a black square.

Both original images seem to be the same - and do display correctly on windows 7.

The images:

works.png:

enter image description here

doesntwork.png:

enter image description here


Solution

  • Works for me using convert -versionImageMagick 6.4.0 04/17/08 Q16 (which is the "Current" version under cygwin), running via cygwin on Windows XP SP3.

    It may be a bug in your particular version of ImageMagick. The shark works.png is a full color image with alpha (4 8-bit channels). The doesntwork.png is a 1-bit black and white image with 8 bits of alpha, and the shading is done by varying the alpha. That seems to me a rather rare format, so I can imagine a bug slipping into the conversion code.

    You might try converting the image to true color first.