-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add animated gif support #3
Comments
libvips can load all the frame in an animated GIF with n=-1, it's saving that's not supported. Looking at the output, it doesn't seem to note the frame times, that's something we should fix:
I think the big problem with write is generating the best palette, and perhaps doing inter-frame optimisation. We should probably add a dependency to a specialist library for this. If we just want a simple, quick hack, we could make a 3:3:2 cube palette and dither with that. We could also record the palette used for load, and recode with that on write. This could be a bit slow though: you'd probably need to build a large table to avoid a search for each pixel. |
Oh haha, and the |
OK, I now see:
There should be a |
So, there's basic animated gif support now, but you need to fallback to the imagick library (in imagine) to use this which seems the more proper way than integrating that in the vips adapter itself. To use it, do it like that: (most operations on the library don't support layers yet, but that's easy to change)
It's currently only in The gif won't be highly optimized, but good enough for later optimization. |
We could at least do now this in the above example
|
Tested now that gif-loops value. I assume the "unit" of that is "ticks" and a second has 100 ticks in gif (so the unit is "10ms"). But with playing around with it, I encountered something strange. I have this image (sorry for the nervous thing, should find a better one ;)) I set the delay to 40ms (or 4 ticks), which is what the original uses. imagemagick Bug or is imagemagick not setting some global delay correctly? |
The original btw shows the "right" gif-delay value, I uploaded it here: libvips/php-vips-ext#16 (comment) (linking to avoid more nervousness here ;)) |
libvips is just attaching the number in the gif header, which I think is 1/100ths of a second. I agree, I see something different from identify. What is "ticks", exactly? Could it be 1/60ths of second, the frame time for most displays? |
No idea where the ticks come from, just saw it here
|
just some random input without having followed everything: i remember from creating animations that each layer can have an individual time how long its displayed. afaik there is no regular clock interval in an animated gif. but maybe imagemagick does something extra on the way to convert to movie formats. |
@dbu at least the Imagine layer only has a global delay option. But you're right that an animated gif can have different delays per frame. |
It looks like ticks defaults to 1/100th, but you can change it. https://www.imagemagick.org/discourse-server/viewtopic.php?t=14739 I can't get identify to report the delay consistently. For your GIF I see:
I'm not sure what to do now. I'll have a look at looping instead. |
maybe imagemagick sets some global header to some value noone else is actually using.
vipsheader also reports 16 when I convert another image with another delay. |
OK, we have |
16 was the default value vips was using. I've changed it to default to 4, so it should match IM. Thanks for the
\o/ |
Delay looks fine now after some quick tests. Loop although always reports '0' for me (again with convert by imagemagick)
|
Argh I'd misunderstood how extension blocks worked. It seems to be OK now. |
Looks better, but is there an off-by-one error now?
(the last one is correct ;)) |
oh, found another issue with gif-delay: following code for http://files.chregu.tv/liip-blog-animated.gif
Result: 116 (there are 96 frames) Without
Result the to be expected 4
|
That's with IM 7.0.3, if that makes any difference. |
gifload is reporting the last delay it saw, and the final frame of your logo animation has a time of 116. Perhaps it should only report the first time? |
OK, only the first delay is reported now. |
Oh, didn't check that the last delay is longer than the first. Sorry about that, but certainly makes more sense to report the first one. |
This is good enough for now. Closing issue finally. |
As libvips doesn't support animated gifs, we maybe can fallback to gifsicle for this.
Example code for creating one from an existing animated gif
We could of course also use imagick to do something similar instead of gifsicle, eg. the
identify -verbose
command (also available in PHP imagick) gives you also all the "delay, loop" information one needs, see http://www.imagemagick.org/Usage/scripts/gif2anim for inspiration. And maybe better to rely on a php extension than a CLI. gifsicle of course makes the more optimized gifs, but that could be another step.The text was updated successfully, but these errors were encountered: