Convert does not preserve transparency

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
ggeeoo

Convert does not preserve transparency

Post by ggeeoo »

Convert does not preserve transparency for some png files that I have. This only happens with the Q16 build. The Q8 works just fine. I had this issue with 6.4.0-9 under Linux and Windows. Here's one of the files that exemplify the problem. I used the following command:

Code: Select all

convert 1.png 2.png
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Convert does not preserve transparency

Post by magick »

We tried your command with ImageMagick 6.4.0-10, the current release, at Q16 and the conversion went as expected (both images were identical).
ggeeoo

Re: Convert does not preserve transparency

Post by ggeeoo »

I tried 6.4.0-10 Q16 under Linux and Windows and had the same problem. It seems that the original image is problematic. I tried to open and then save it with several programs and it worked correctly (ie the transparency is preserved) with the exception of Photoshop and ImageMagick Q16. GIMP gave the following error message "Image resolution is out of bounds, using the default resolution instead" but rendered the image correctly.
User avatar
rmabry
Posts: 148
Joined: 2004-04-13T11:25:27-07:00

Re: Convert does not preserve transparency

Post by rmabry »

Same problem today, Windows 7, ImageMagick 6.6.7-0 2011-01-01 Q16. Using the image here,

http://www.maik-juergens.de/imagemagick/image1.png

I run

Code: Select all

convert image1.png image1-copy.png


and get a copy with no transparency.

Code: Select all

identify image1.png
image1.png PNG 46x48 46x48+0+0 8-bit DirectClass 538B 0.000u 0:00.000

identify image1-copy.png
image1-copy.png PNG 46x48 46x48+0+0 8-bit PseudoClass 49c 654B 0.000u 0:00.000
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Convert does not preserve transparency

Post by glennrp »

It is working for me (IM-6.6.7-1, Q8 and Q16). The resulting images are indeed PseudoClass (paletted PNG, color-type 3), but they have a tRNS chunk to convey the transparency.

If you are using a viewer that cannot handle this type of image, then use

Code: Select all

convert image1.png PNG32:image1-copy.png
to force IM to write an RGBA PNG.

Pngcrush -n -v reports:
  • Found tRNS chunk in input file.
    png_set_tRNS, num_trans=45
    Palette:
    I R G B ( color ) A
    0 255 255 255 (#ffffff) 0
    1 33 160 210 (#21a0d2) 14
    2 33 160 210 (#21a0d2) 83
    3 33 160 210 (#21a0d2) 144
    4 33 160 210 (#21a0d2) 194
    5 33 160 210 (#21a0d2) 232
    6 33 160 210 (#21a0d2) 253
    7 141 210 33 (#8dd221) 253
    8 141 210 33 (#8dd221) 232
    9 141 210 33 (#8dd221) 194
    10 141 210 33 (#8dd221) 144
    11 141 210 33 (#8dd221) 83
    12 141 210 33 (#8dd221) 14
    13 33 160 210 (#21a0d2) 94
    14 33 160 210 (#21a0d2) 185
    15 141 210 33 (#8dd221) 185
    16 141 210 33 (#8dd221) 94
    17 33 160 210 (#21a0d2) 29
    18 33 160 210 (#21a0d2) 142
    19 141 210 33 (#8dd221) 142
    20 141 210 33 (#8dd221) 29
    21 33 160 210 (#21a0d2) 158
    22 141 210 33 (#8dd221) 158
    23 210 54 33 (#d23621) 253
    24 210 146 33 (#d29221) 253
    25 210 54 33 (#d23621) 232
    26 210 146 33 (#d29221) 232
    27 210 54 33 (#d23621) 194
    28 210 146 33 (#d29221) 194
    29 210 54 33 (#d23621) 144
    30 210 146 33 (#d29221) 144
    31 210 54 33 (#d23621) 83
    32 210 146 33 (#d29221) 83
    33 210 54 33 (#d23621) 14
    34 210 54 33 (#d23621) 185
    35 210 146 33 (#d29221) 185
    36 210 146 33 (#d29221) 14
    37 210 54 33 (#d23621) 94
    38 210 146 33 (#d29221) 94
    39 210 54 33 (#d23621) 142
    40 210 146 33 (#d29221) 142
    41 210 54 33 (#d23621) 29
    42 210 54 33 (#d23621) 158
    43 210 146 33 (#d29221) 158
    44 210 146 33 (#d29221) 29
    45 33 160 210 (#21a0d2) 255
    46 141 210 33 (#8dd221) 255
    47 210 54 33 (#d23621) 255
    48 210 146 33 (#d29221) 255
Note that all but the last four colors in the palette have some degree of transparency.
If you look at the result of "identify -verbose image1.png | grep signature'
and repeat for the output image you will find that the signatures are the same.
User avatar
rmabry
Posts: 148
Joined: 2004-04-13T11:25:27-07:00

Re: Convert does not preserve transparency

Post by rmabry »

Hi Glenn,

Thanks, that works and solved related problems for me.

So (I address this to to one and all), another lesson here is that convert with no parameters should not be expected to act as a copy command. [Edit: I mean, of course, where the input and output formats match.] I have been under the opposite impression for quite a while. Is there then a set of default attributes that one should expect to be preserved? A set of attributes of a given format that is expected to be imposed? Is this somewhere writ?

Rick
Post Reply