Skip to content

Transparency in PNG is ignored in some cases #186

Open
@melonmouse

Description

@melonmouse

ImageMagick version

6.9.12-50 Q16 x86_64 17254
libpng 1.6.37
GIF version 87a

Operating system

Linux

Operating system, version and so on

Fedora 35, version 5.17.13-200.fc35.x86_64

Description

Using convert in.png out.gif should preserve any transparency in the png (this is especially relevant when dispose=1). This works properly in most cases, but depending on the input png, the background is sometimes incorrectly replaced with (0,0,0). I found a somewhat stable neighborhood of failing inputs, and some very similar inputs that are working properly. Surprisingly, the only difference between the input PNGs that cause imagemagic to fail is pixel data. This points to some failing heuristic or a bug that depends on the input.

Example input PNG + output gif, where imagemagic does not preserve transparency:
overlay_bad15 a

Example input PNG + output gif, where imagemagic does preserve transparency:
overlay_good6 b

Note that I encountered this bug in the wild several times before filing this bug. The above images were simplified to get closer to a minimal example, but it should be noted that this bug is not just fuzzer territory.

P.S. Imagemagic is amazing, thanks so much for working on it! Let me know if I can provide any additional information.

Steps to Reproduce

For each of the files in "example_images.zip" below:
convert overlay_bad###.png test.gif yields a gif without proper transparency.
convert overlay_good###.png test.gif yields a gif with proper transparency.

Images

Zip with 17 failing images (overlay_bad###.png) and 6 working images (overlay_good###.png):

example_images.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions