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

No pages metadata for animated gif #1566

Closed
jaubourg opened this issue Feb 4, 2019 · 15 comments
Closed

No pages metadata for animated gif #1566

jaubourg opened this issue Feb 4, 2019 · 15 comments

Comments

@jaubourg
Copy link
Contributor

jaubourg commented Feb 4, 2019

Maybe I'm doing something wrong but whenever I load an animated gif and do operations on it, I always end up with the first frame transformed and that's it.

In order to determine if this was due to something deep into our code, I looked more closely into the metadata reported by sharp for animated gifs.

From what I understand from the docs, an animated image is supposed to give a pages value that is a number.

If I input an animated monkey found online, I end up with a metadata.pages that's undefined and sharp only acts on the first frame.

Is this by design? Am I missing something?

Also, I saw outputting animated webp was supported but is outputting apng supported too? Could be nice to have a clear support grid somewhere in the docs where this kind of things would be listed. But I know how difficult and time-consuming writing docs can be ;)

@lovell
Copy link
Owner

lovell commented Feb 5, 2019

Bonjour, it looks like sharp needs to expose libvips' n property on the input so a caller can request all frames (with GIF you have to decode all the frames to find out the frame count and dimensions).

At the command line i see:

$ vipsheader -a small-animated-hear-see-speak-no-evil-moving-monkey.gif | grep page
$ vipsheader -a small-animated-hear-see-speak-no-evil-moving-monkey.gif[n=-1] | grep page
page-height: 157

So it looks like libvips itself also needs to expose the GIF page count too.

@lovell lovell added the bug label Feb 5, 2019
jcupitt added a commit to libvips/libvips that referenced this issue Feb 9, 2019
gifload was not setting the n-pages metadata item.

n-pages is supposed to be the number of pages in the original file (not
the number of pages libvips loaded), but we don't always know this for
gif, since you have to decode the entire file to count the pages.

As a compromise, set it to the page number of the final page we read.

See lovell/sharp#1566
@jaubourg
Copy link
Contributor Author

I dunno if this is related but I see not pages metadata for the following apng and animated webp image:

@jaubourg
Copy link
Contributor Author

jaubourg commented Feb 12, 2019

I also get a Error: webp2vips: unable to read pixels when I try and do any action on the webp above except getting metadata. Metadata show it's 400x400 though.

@lovell
Copy link
Owner

lovell commented Feb 13, 2019

The forthcoming libvips v8.8.0 will add support for animated WebP.

libpng does not support animated PNG.

@jaubourg
Copy link
Contributor Author

Ah that makes sense now. Thanks @lovell :)

@lovell
Copy link
Owner

lovell commented Mar 17, 2019

Commit 9cc06c8 expose libvips' n parameter as the pages input option to select how many pages to load. This will be in v0.22.0.

@lovell lovell added this to the v0.22.0 milestone Mar 17, 2019
@lovell
Copy link
Owner

lovell commented Mar 19, 2019

v0.22.0 now available.

@lovell lovell closed this as completed Mar 19, 2019
@RaboliotLeGris
Copy link
Contributor

Salutations!

I think it's related to this issue.

I'm using sharp 0.22.1 and I'm trying to extract the number of pages of a GIF to determine if it's a animated one. But each time the metadata doesn't contains the pages attribute.

I've tried with several GIF picked on the web and also with the one that Jaubourd provides.

Here is a small standalone that show the issue.

wget http://www.netanimations.net/small-animated-hear-see-speak-no-evil-moving-monkey.gif
node -e "require('sharp')('small-animated-hear-see-speak-no-evil-moving-monkey.gif').metadata().then((meta) => console.log(meta, meta.pages))"

Am I missing something ? :)

@lovell
Copy link
Owner

lovell commented May 23, 2019

It looks like libvips 8.8.0 is required for the pages property - see libvips/libvips@2968bee

@tomgallagher
Copy link

Hi Lovell, hope you're well.

Am I right in saying animated gif input to animated webp output will be possible in the near-ish future?

@lovell
Copy link
Owner

lovell commented May 24, 2019

@tomgallagher libvips v8.8.0 supports this.

@tomgallagher
Copy link

tomgallagher commented May 25, 2019

And lipvips v8.8.0 may be included in Sharp 0.23.0?

@lovell
Copy link
Owner

lovell commented May 25, 2019

@tomgallagher Yes, that's the plan.

@tomgallagher
Copy link

Great. Thanks.

@tomgallagher
Copy link

@lovell If the Sharp API need to change to accommodate libvips v8.8.0, I can help with the documentation if that's plausible and time-saving.

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

4 participants