Skip to content

Gifs sometimes get optimized incorrectly #2288

Description

@SigmundurMorkore

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

v2.1.3

Other ImageSharp packages and versions

ImageSharp.Web 2.0.2

Environment (Operating system, version and so on)

Linux and Mac

.NET Framework version

6

Description

When doing any processing on some gifs, the output isn't correct.

Example 1
This is the original gif:
51819_osvart_orkushow
When sending it through ImageSharp.Web with any query parameters, even inconsequential ones, the output gif is extremely slow (with rmode=crop):
imagesharp-51819_osvart_orkushow

Example 2
This is the original gif:
irishpublysing
When sending it through ImageSharp.Web with any query parameters, even inconsequential ones, the output gif has the first "V" in the smaller text almost turned into a "M" (with rmode=crop):
imagesharp-irishpublysing

Steps to Reproduce

  1. Run a gif through ImageSharp.Web
  2. It may or may not have things that are incorrect

Images

51819_osvart_orkushow
imagesharp-51819_osvart_orkushow

irishpublysing
imagesharp-irishpublysing

Activity

  1. JimBobSquarePants commented on Nov 7, 2022

    @JimBobSquarePants
    Member

    I think the issue here is that we always encode the GraphicsControlExtension even though it is optional. I should be able to code up a workaround to prevent this.

    It's actually the opposite. We've been ignoring the extension if the delay is 0.

    Here's a version using my local changes.
    OptionalExtensionsAreNotEncoded_Rgba32_issue_2288

  2. added this to the 3.0.0 milestone on Nov 7, 2022
  3. SigmundurMorkore commented on Nov 7, 2022

    @SigmundurMorkore
    Author

    @JimBobSquarePants awesome :D

    Is the weird artifacting (around the "V") in the second example a separate issue?

  4. JimBobSquarePants commented on Nov 7, 2022

    @JimBobSquarePants
    Member

    Ah... Didn't spot that. Separate issue. Not sure what the cause is there....Yet

  5. JimBobSquarePants commented on Nov 7, 2022

    @JimBobSquarePants
    Member

    OK. The issue there is that the image contains both global and local color tables but we only support one or the other.

    BTW. I wouldn't currently recommend resizing/cropping multi-frame gifs in this manner with ImageSharp. Unfortunately, a current architectural limitation requires that all frames are the same size so each frame is padded if smaller to match. This can lead to multi-frame images being much larger following processing than the input.

  6. SigmundurMorkore commented on Nov 7, 2022

    @SigmundurMorkore
    Author

    Aah I see, makes sense 👍

    Is it possible for ImageSharp to implement support for gifs with both kinds of color tables?
    I may want to look into a tool that can convert gifs with both global and local color tables to just use one or the other.

    Thanks for the info on resizing/cropping!

  7. JimBobSquarePants commented on Nov 7, 2022

    @JimBobSquarePants
    Member

    It's absolutely possible. Working on a fix just now. Might take me a few days though.

  8. JimBobSquarePants commented on Nov 7, 2022

    @JimBobSquarePants
    Member

    OptionalExtensionsShouldBeHandledProperly_Rgba32_issue_2288_2

    Got some cleanup and investigation to do but this is major progress

  9. SigmundurMorkore commented on Nov 7, 2022

    @SigmundurMorkore
    Author

    That looks perfect! ❤️

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions