#10 Paletted PNG with alpha channel

v1.0_(example)
closed
None
5
2014-01-06
2011-12-28
Gato
No

I'm trying to reduce the file size of some images by converting them from true color to paletted. The problem seems to be those images have an alpha channel.

I'm using something like:

gm convert -colors 256 -type Palette in.png out.png

However, I'm getting the following error: convert: Can't write tRNS with an alpha channel (out.png)

PNG files can store an alpha channel even with paletted images, so I guess what I want to do should be possible with gm. Am I doing something wrong or is this something not (yet) supported?

Discussion

    • assigned_to: nobody --> glennrp
     
  • Does -colors 255 work? Sometimes GM notices that there are 256 colors present after the reduction, plus the background color, if the background color isn't in the colormap. Therefore there are 257 colors in all, which won't fit
    in the PNG palette, so it writes a truecolor image instead of an indexed image, and then complains about the
    tRNS chunk.

    I think the same thing happens with 2, 4, and 16 colors, because there's no room for the background color
    in the 1-bit, 2-bit, or 4-bit palette.

     
  • Gato
    Gato
    2011-12-28

    No, I get the same message with 255, or almost any other value I pick. However, if I go down to 16, I get another message:

    gm convert: Invalid IHDR data (out.png)

     
  • Gato
    Gato
    2011-12-28

    This is one of the images I'm trying to convert

     
    Attachments
  • verified that the gm14 snapshot exhibits this problem:

    gm convert | head -2
    GraphicsMagick 1.4 snapshot-20111208 Q8 http://www.GraphicsMagick.org/
    gm convert logo: -resize 200% -transparent white -matte p01in.png
    echo 256 colors
    gm convert -colors 256 -type Palette p01in.png p01out256.png
    echo 255 colors
    gm convert -colors 255 -type Palette p01in.png p01out255.png
    echo 254 colors
    gm convert -colors 254 -type Palette p01in.png p01out254.png

    All 3 tests fail:256 colors
    gm convert: Invalid background palette index (p01out256.png).
    255 colors
    gm convert: Invalid background palette index (p01out255.png).
    254 colors
    gm convert: Invalid background palette index (p01out254.png).

    (which is not exactly the error message that you reported)

     
  • Testing shows that this problem is fixed in the current release. Yay!

     
    • status: open --> closed
    • Group: --> v1.0_(example)