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

Support animated gifs with a transparent background #653

Open
mhme2000 opened this issue Nov 6, 2024 · 21 comments
Open

Support animated gifs with a transparent background #653

mhme2000 opened this issue Nov 6, 2024 · 21 comments

Comments

@mhme2000
Copy link

mhme2000 commented Nov 6, 2024

Does the library support gifs with a transparent background? Do I have to pass any specific configuration for this to work?

@mhme2000
Copy link
Author

mhme2000 commented Nov 6, 2024

Original gif example ->
5fa97d9c-59a1-40e2-8831-bc5df357f6d7

GIF served by the app using imageflow-server ->
image

@mhme2000 mhme2000 changed the title Gifs with a transparent background Support gifs with a transparent background Nov 6, 2024
@henriqueholtz
Copy link

UP! I'm into the same issue here, using the version 0.8.3 (currently the latest).

@Matheus-Sleutjes
Copy link

UP! I'm having the same problem

@mhme2000
Copy link
Author

mhme2000 commented Nov 8, 2024

Simplest step-by-step guide to reproduce:

Clone this repository and run the project ExampleMinimal, inserting the image passed into the wwwroot folder.

image

image

5fa97d9c-59a1-40e2-8831-bc5df357f6d7

@antoniomelotraycorp
Copy link

UP

@gaabrielalex
Copy link

UP! Estou com o mesmo problema

@GustavoEckart
Copy link

Hey everyone! I’m also having this issue with transparent GIFs. Has anyone found a temporary solution?

@HellderCardoso
Copy link

HellderCardoso commented Nov 11, 2024

UP! I'm having the same problem =/

@lilith
Copy link
Member

lilith commented Nov 12, 2024 via email

@mhme2000
Copy link
Author

@lilith Could these be packages? I don't have them as a direct dependency, but the dlls are generated after the application is built.

image

image

We only have these two direct dependencies in the project:

Imageflow.Server Version="0.8.3"

Imageflow.Server.HybridCache Version="0.8.3"

@lilith
Copy link
Member

lilith commented Nov 12, 2024

https://www.nuget.org/packages/Imageflow.AllPlatforms/#versions-body-tab

Imageflow.AllPlatforms bundles all the Imageflow.NativeRuntime.* dependencies for you.

The versions of those packages are what matter. If you update Imageflow.AllPlatforms, does the issue persist?

@mhme2000
Copy link
Author

@lilith yes, the issue persists.

image

@lilith
Copy link
Member

lilith commented Nov 12, 2024

0.13.2 is the latest, not 0.10, based on the screenshot that's a 2yo version.

@mhme2000
Copy link
Author

image

image

@lilith I'm sorry, I sent the wrong printscreen. But the error persists.

@lilith
Copy link
Member

lilith commented Nov 12, 2024

Ok. Can you access /imageflow.debug, share that with me (email is fine), along with the exact image files that are not working for you?

@lilith
Copy link
Member

lilith commented Nov 12, 2024

Also, some browers make the backgroud white, some black, so make sure you test transparent images against something of a different color.

@henriqueholtz
Copy link

Any updates here?

@lilith
Copy link
Member

lilith commented Nov 22, 2024 via email

@lilith lilith changed the title Support gifs with a transparent background Support animated gifs with a transparent background Dec 4, 2024
@lilith lilith transferred this issue from imazen/imageflow-server Dec 4, 2024
@lilith
Copy link
Member

lilith commented Dec 4, 2024

Animated, transparent gifs are an extremely difficult corner case. Specifically, supporting this includes:

  1. Decoding each frame, compositing it against the previous frames while preserving the transparency indexed color, working in indexed mode, and keeping timing and repeat information
  2. Doing all the normal image processing such as resizing, sharpening, effects
  3. Re-quantizing the result while finding a reasonable compromise for transparent pixels, since GIF does not support partial transparency, only opaque or invisible. Palette magic must ensure that there is overlap with the global and prior frame palettes to keep the transparent index consistent.
  4. Since there's no way to mark a pixel as transparent on a frame, only relative to previous frames, to preserve transparency all prior frames must have the same pixel marked as transparent
  5. Diff the current frame and prior frame and crop to the area that is actually different, positioning that rectangle and providing just that area. Re-encoding and attempting to avoid palette bloat, but also not eliminating colors unique to the frame. Doing this optimally is a massive task, even more so if you try to achieve true-color hacking (at the expensive of massive file size).
  6. Encode and compress

I'm estimating the entire encoding pipeline would need to become quite a bit slower to account for this, possibly making real-time difficult. After a few days of working on this, I'm going to put this on the backlog, and suggest that animated AND transparent gifs be an offline task, and consider gifski.

lilith added a commit that referenced this issue Dec 4, 2024
…ed gifski due to animated+transparent re-encoding complexity. To solve #653
@lilith
Copy link
Member

lilith commented Dec 4, 2024 via email

@mhme2000
Copy link
Author

mhme2000 commented Dec 4, 2024

Okay, got it. Is there any simple way to ignore .gif files in the imageflow middleware? And process this file in another way, without going through the lib?

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

No branches or pull requests

8 participants