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

Animated GIF support #246

Merged
merged 9 commits into from
Jan 15, 2022

Conversation

Elad-Laufer
Copy link
Contributor

@Elad-Laufer Elad-Laufer commented Jan 13, 2022

  • Export native of GIF
  • Support animated images resize
  • Support animated images rotate
  • Load from file with import options

elad laufer added 2 commits January 12, 2022 12:44
- export GIF
- resize animated images
- export animated images
@coveralls
Copy link

coveralls commented Jan 13, 2022

Coverage Status

Coverage increased (+0.5%) to 76.054% when pulling 164901c on wix-incubator:animated-gif-support into 423eb69 on davidbyttow:master.

elad laufer added 5 commits January 13, 2022 14:16
- when building ImageMetadata add all the props
- Add imageRef.Grid() func
- rename ...pages... functions to something more reasonable
- fix 270 rotation of multi-page images
- Pages() instead of GetPages() is more Go like
- Orientation() instead of GetOrientation() is more Go like
@Elad-Laufer Elad-Laufer marked this pull request as ready for review January 14, 2022 10:55
@davidbyttow
Copy link
Owner

Resolve conflicts?

@Elad-Laufer
Copy link
Contributor Author

Resolve conflicts?

done

@AttilaTheFun
Copy link
Contributor

I'm super excited for this to land! Right now I have some "if-gif" code to fall back on the builtin image package when dealing with gif images that I would love to delete.

@davidbyttow davidbyttow merged commit 623c60d into davidbyttow:master Jan 15, 2022
@AttilaTheFun
Copy link
Contributor

Awesome! @davidbyttow could we cut a new release including this commit?

@davidbyttow
Copy link
Owner

Done! https://github.com/davidbyttow/govips/releases/tag/v2.10.0 @AttilaTheFun

@AttilaTheFun
Copy link
Contributor

Sweet I'll try it out later today. If I recall before, gifs would break when I tried to resize them.

As a result I had to store gifs in a separate S3 bucket with a separate CloudFront bucket which had my Lambda@Edge function disabled.

If gif resizing is working now, I'd be excited to unify gifs with the rest of the images on my server.

@AttilaTheFun
Copy link
Contributor

AttilaTheFun commented Jan 18, 2022

@davidbyttow @Elad-Laufer So I just pulled down this version and tested it out but I'm still seeing the same issue I saw before. If I import a GIF from a file and then export it back to a file, it only seems to write the first frame of the GIF.

I'm not sure if this is still broken or if I'm "holding it wrong", but I've attached the images I used to test:

Original VIPS
sRGB IEC61966-2 1 sRGB IEC61966-2 1 Encoded

I'm importing the image from a file handle like so:

	img, err := vips.NewImageFromReader(reader)
	if err != nil {
		return nil, err
	}

And then I'm exporting it this way:

	ep := vips.NewGifExportParams()
	bytes, _, err := img.ExportGIF(ep)
	if err != nil {
		return nil, err
	}

And writing the bytes back to the new file. Is this supposed to be working? Or is there another way to import / export GIFs I should be using?

UPDATE: I found the test case that was added and saw that you must explicitly set the number of pages to -1 when importing a GIF. Once I did that it worked.

	importParams := vips.NewImportParams()
	importParams.NumPages.Set(-1)
	img, err := vips.LoadImageFromBuffer(buf, importParams)
	if err != nil {
		return nil, err
	}

That said, I believe defaulting to only loading the first frame of a GIF is a bad UX. I'd advocate for making the default value be -1 so that importing and exporting an image with the default parameters would round trip.

@Elad-Laufer
Copy link
Contributor Author

Elad-Laufer commented Jan 18, 2022

That said, I believe defaulting to only loading the first frame of a GIF is a bad UX. I'd advocate for making the default value be -1 so that importing and exporting an image with the default parameters would round trip.

I agree, but that would change the current behavior and break backwards compatibility in an unexpected way as it will compile just fine and will behave differently. For example, when converting an animated image to a format that does not support animation such as JPEG, if more than one page is loaded the exported image will be the entire roll and not a single frame (which defaults to the first one).

This is probably another good point to consider in #248.

@davidbyttow
Copy link
Owner

There could be NewGifImportParams()?

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

Successfully merging this pull request may close these issues.

4 participants