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

Transparent background for GIF #82

Closed
bipinkrish opened this issue Mar 18, 2024 · 9 comments
Closed

Transparent background for GIF #82

bipinkrish opened this issue Mar 18, 2024 · 9 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@bipinkrish
Copy link
Contributor

bipinkrish commented Mar 18, 2024

I would be good idea to save gif with transparent background by default then white background so it suits for most of the users.

Just need to set alpha channel value 0 here

@AmitMY
Copy link
Collaborator

AmitMY commented Mar 19, 2024

I agree that it would be best to save gifs with transparency.
I'll be honest - I didn't know that the GIF format even supported transparency, but just learned that it is only partial:

the GIF format doesn't support partial (alpha-channel) transparency

I don't have time to look into this in the next week or so, so I invite you to contribute this modification if you want it soon.

@AmitMY AmitMY added enhancement New feature or request help wanted Extra attention is needed labels Mar 19, 2024
@bipinkrish
Copy link
Contributor Author

I tried to do it, I got transparent background but hand movements become clustered and it wasn't smooth, I cant figure out why would background color change affects the hand motion.

@AmitMY
Copy link
Collaborator

AmitMY commented Mar 19, 2024

If you create a PR, and specify the issue (with an example GIF), I might be able to look at it faster

@bipinkrish
Copy link
Contributor Author

sure

@bipinkrish
Copy link
Contributor Author

I will soon open a PR to show the changes but this is the result

Expected:

pose-unscreen

Actuall:

pose-transparent

@AmitMY
Copy link
Collaborator

AmitMY commented Mar 19, 2024

Ah! so the issue is probably this one https://stackoverflow.com/questions/60948028/python-pillow-transparent-gif-isnt-working

You have not specified the disposal parameter of Image.save(). This parameter controls how the previous frame is disposed in relation to the background. If unspecified, the previous frame "lingers" into the next frame(s). Adding disposal=2 should resolve that particular issue.

@bipinkrish
Copy link
Contributor Author

Yeah according to this GIF has border problems but APNG doesn't have that

GIF:

pose.gif

PNG :

pose.png

Should I stick with PNG?

@AmitMY
Copy link
Collaborator

AmitMY commented Mar 21, 2024

Glad to see you got it working.
Personally, for a moving video, I would choose webm. If you can't use a video, webp would be a good alternative.
if you really want to use gif, maybe there's a way to set the border's alpha to 0, which will fix the white patches

@AmitMY
Copy link
Collaborator

AmitMY commented Mar 21, 2024

Thanks for solving your issue!

@AmitMY AmitMY closed this as completed Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants