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 does not work as expected in gif creation #3

Open
ojensen5115 opened this issue Feb 22, 2020 · 8 comments
Open

Transparency does not work as expected in gif creation #3

ojensen5115 opened this issue Feb 22, 2020 · 8 comments

Comments

@ojensen5115
Copy link
Contributor

Thank you for this excessively fun implementation! While playing around with it, I noticed that transparency doesn't seem to work quite right in GIF mode.

When glitching a reasonably complex image with a transparent background, the background appears to turn black:
square2 glitched_square2

Interestingly, when glitching a single-color image with a transparent background, I get a black background again but the blue rectangle has become transparent:
square glitched_square

As such, I suspect this results from not keeping a constant palette when operating over the individual frames. Note that this seems to occur during the final combination and saving of the frames, as the individual frame files written to the Glitched GIF directory all appear to be correct.

@TotallyNotChase
Copy link
Owner

weird, do you think it's something to do in this line?
I'll have to take a look soon

@ojensen5115
Copy link
Contributor Author

ojensen5115 commented Feb 22, 2020

I suspect so. As best as I can tell, it looks like this stems from the different frames having different palettes which don't line up (i.e. transparent in frame 0 might be the palette index of blue in frame 3). The second (single color) example above seems to corroborate the idea of palette indexes getting swapped around.

I spent an hour or so this morning reading through pillow docs and issues, and while there's a lot around transparency behaving weird, I didn't see anything that seems to match this issue entirely and most of the issues seemed like they had already been resolved.

I'm sorry I can't be of more help, I'll continue looking around and seeing what I can find.

@ojensen5115
Copy link
Contributor Author

If anyone needs a quick workaround: the individual layer files are no longer deleted after run, so you can just package them up into a gif manually using your favorite gif-capable image editor (e.g. gimp, etc.)

@TotallyNotChase
Copy link
Owner

Looks like this is no longer possible as the library cleans up after itself now.

@ethanopp
Copy link

Any update on this? I'm noticing it only happening when color_offset=True

@TotallyNotChase
Copy link
Owner

@ethanopp Haven't quite gotten the time to investigate this further, unfortunately. But as ojensen said, it does seem to be an issue with the pillow .save method losing the alpha channel for some reason.

If you're interested in investigating this - I'd say that an easy fix may involve checking if RGBA is being used for the final save, if it's not being used, it should start being used unless it causes issues for other usecases. If there's no fix possible on the .save method itself (unlikely), then the saved gif (that is not transparent correctly) will need to be alpha composed with another image to make the specific parts of the image transparent - though this will be much more time consuming.

@ethanopp
Copy link

Ended up using this and it seems to be working:
python-pillow/Pillow#4644

@agentx3
Copy link

agentx3 commented Apr 26, 2022

Not sure if things are different now than before since I just started using this. But it appears that even when I save each individual layer it appears that each have also lost their transparency. I've tried some of the methods in the above comment to no avail. What I do notice it seems that this happens in particular only to larger resolution files.

EDIT: Nevermind??? I think I'm trippin' balls here. I'm running the solution from https://gist.github.com/egocarib/ea022799cca8a102d14c54a22c45efe0 and it works just fine??? It's suddenly working.

What's nice about this one is save_transparent_gif already uses List[Image] as the Type whereas the above comment one doesn't.

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

No branches or pull requests

4 participants