Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparency in PNG is ignored in some cases #186

Open
melonmouse opened this issue Jun 16, 2022 · 5 comments
Open

Transparency in PNG is ignored in some cases #186

melonmouse opened this issue Jun 16, 2022 · 5 comments

Comments

@melonmouse
Copy link

melonmouse commented Jun 16, 2022

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

@melonmouse
Copy link
Author

Potentially, ImageMagick/ImageMagick#3599 is related.

@melonmouse
Copy link
Author

I was unable to reproduce this bug when using ImageMagick 7.1.0-37 Q16-HDRI x86_64 b65d0d9af:20220605
magick in.png out.gif.

@dlemstra
Copy link
Member

It looks like this has to do with color reduction and that works different between IM6 and IM7. I am getting consistent results with the following command: convert input.png -type palettebilevelalpha -colors 256 output.gif

@fmw42
Copy link

fmw42 commented Jun 26, 2022

Why is it different and how?

@dlemstra dlemstra transferred this issue from ImageMagick/ImageMagick Jun 26, 2022
@fmw42
Copy link

fmw42 commented Jun 26, 2022

PNG has 8-bit transparency. GIF is only binary transparency. So when converting a PNG to GIF the transparency is effectively thresholded to black and white and the partial transparency is lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants