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 WebP resize doesn't keep loop and delay #1615

Closed
georgiopandarez opened this issue Apr 21, 2020 · 5 comments
Closed

Animated WebP resize doesn't keep loop and delay #1615

georgiopandarez opened this issue Apr 21, 2020 · 5 comments
Labels

Comments

@georgiopandarez
Copy link

Hi,

When resizing an animation (webp or gif), metadata is lost and the resulting image is not animated. Converting animation without resizing works fine. Tested against debian libvips42 and latest master.

  • vipsthumbnail -s 200x200 -o /tmp/gif.webp samples/animated.gif

  • vipsheader -a /tmp/gif.webp
    /tmp/gif.webp: 200x116 uchar, 3 bands, srgb, webpload
    width: 200
    height: 116
    bands: 3
    format: uchar
    coding: none
    interpretation: srgb
    xoffset: 0
    yoffset: 0
    xres: 1
    yres: 1
    filename: /tmp/gif.webp
    vips-loader: webpload

@jcupitt
Copy link
Member

jcupitt commented Apr 21, 2020

Hello @georgiopandarez,

By default, it'll just process the first frame -- you need to ask for all frames. Try:

vipsthumbnail something.gif[n=-1] -s 200x200 -o x.gif

You can use page= and n= to select a range of pages in the image to thumbnail. n=-1 means all pages.

@georgiopandarez
Copy link
Author

georgiopandarez commented Apr 22, 2020

Hi!

Thanks for the prompt reply. The issue seems to be when resizing and converting. ie

vipsthumbnail something.gif[n=-1] -s 200x200 -o x.webp

This results in an image with no animation.

The below python also shows issues:

image = pyvips.Image.gifload(sys.argv[1], access="sequential", n=-1)
dim = int(sys.argv[2])
resized_image = image.resize(dim / image.width, vscale=dim / image.height)
resized_image.webpsave(sys.argv[1] + ".webp")
image.webpsave(sys.argv[1] + ".noresize.webp")

The resized webp version shows a single image with the frames on top of each other. The resave shows an image without animation. Does one need to manually calculate page_height?

@jcupitt
Copy link
Member

jcupitt commented Apr 22, 2020

It should work, I think. With this GIF:

dancing-banana

If I run:

vipsthumbnail dancing-banana.gif[n=-1] -s 200 -o x.webp

I get an animation that plays correctly in chrome (I'd attach it, but github does not allow webp). Do you have an example that fails?

Yes, you have to adjust page-height yourself. thumbnail has extra logic to do this for you.

It's best to use thumbnail if you can -- it also knows about webp shrink-on-load, so it should be much faster than resize.

@georgiopandarez
Copy link
Author

Sorry to waste your time.

My code issue was that image.height returns the height of the image * the number of pages. I needed to take that into account when resizing.

I tried to verify using vipsthumbnail but missed that -o placed the image in the same directory as the input, not relative to the program.

@jcupitt
Copy link
Member

jcupitt commented Apr 23, 2020

Yes, it's relative to the input, so you can do eg.:

vipsthumbnail */*.jpg -o %s-thumbnail.jpg

It's more like a pattern for the output path than a standard -o switch. Anyway, glad it's working.

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

No branches or pull requests

2 participants