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

Converting animated gif to webp produces faulty images #4313

Closed
madeddy opened this issue Dec 29, 2019 · 8 comments · Fixed by #5333
Closed

Converting animated gif to webp produces faulty images #4313

madeddy opened this issue Dec 29, 2019 · 8 comments · Fixed by #5333
Labels
Projects

Comments

@madeddy
Copy link

madeddy commented Dec 29, 2019

What did you do?

Converted some animated gifs to animated webp. Used different qualtity settings.

What did you expect to happen?

Getting a identical converted image. Beside the(logical) format and possible size change.

What actually happened?

Webp outputs are defect. Three different problems appear.
The output images:

  1. play too slow
  2. do not play in a image viewer (gwenview for me OR in Pillow's Image.show() method)
  3. some images have after convert also visual defects like wrong pixels (flickering and line style artifacts)

ps.: Converting the same images with the same settings with webp CLI tools works without issues.

What are your OS, Python and Pillow versions?

  • OS: Kubuntu 18.04.3
  • Python: 3.6.9
  • Pillow: 6.2.1

Code example

Python:

from pathlib import Path as pt
from PIL import Image

src_f = pt("animated.gif")
dst_f = pt(src_f).with_suffix('.webp')

# other used quality settings for fast copy past:
# {'lossless': True} {'allow_mixed': True}
quali = {'quality': 90}

Image.open(src_f).save(dst_f, 'webp', **quali, save_all=True)

Shell variant:

gif2webp -v -lossy -q 90 paris_metro.gif -o paris_metro.webp

Example images

Content of the archive:

  • Two input gifs
  • both output files (converted with "quality 90") with problems 1. and 2.
  • paris_metro.webp has also problem 3. present. (pixel errors are to see while playing)
    anim.tar.gz
@radarhere
Copy link
Member

radarhere commented Dec 29, 2019

I'm unable to replicate 2. The following code works for me with your attached images.

from PIL import Image
Image.open("animated.webp").show()
Image.open("paris_metro.webp").show()

For the record, 3 isn't a problem with WEBP, it's a problem with Pillow loading the GIF.

@radarhere
Copy link
Member

To fix 1, you just need to pass in the duration -

im = Image.open(src_f)
im.save(dst_f, 'webp', **quali, duration=im.info["duration"], save_all=True)

@radarhere radarhere added the GIF label Dec 29, 2019
@madeddy
Copy link
Author

madeddy commented Dec 30, 2019

OK. Lets see.

  1. With duration passed in it works now correct. (What the ...! Not true. I come back to this.)
  2. Was a two pronged problem:
  • Not playing with .show() - i did'n notice it uses a viewer app from underlying OS. So its not pillow related - totally my fault (For me it uses imagemagick and still doesn't play.)
  • Did'n work in Kubuntu's gwenview, but now it does play. Was imo caused by 1.
  1. Um... Does this mean the convert is ok, however the input gets corrupted because of a faulty read in?

Problem 1. is solvable with the mentioned workaround but i consider this now even more a bug as before. Pillow has the input file and can get all needed infos by himself. Or whats next?

Do you find it a acceptable approach if i would make a enhancement issue out of it? Chances? So basically pillow takes the duration in the above fashion, if not passed in by user.

And thanks for taking the time.
Greets

@radarhere
Copy link
Member

radarhere commented Dec 30, 2019

1 - Pillow values backwards compatibility. So I don't think that changing defaults is likely to be accepted.
3 - Saving is ok, but reading is not. This may or may not be helpful to you, but it's more an explanation here.

@madeddy
Copy link
Author

madeddy commented Jan 1, 2020

For 3) Ah no, thats good. The explanation is appreciated. Even if i cannot do anything about it, but i hope you folks find the problem.
For 1) I feared something like this. https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.info A pity.
To get this under control, Pillow would imho need a extended analysis module for the input image attributes with tons of checks and rechecks and compares and tests etc.

So to clears this up: Basically are the problems 1 and 2 resolved by a workaround. The docs should mention this in a more visible way.

@aclark4life aclark4life added this to New Issues in Pillow Jan 9, 2020
@radarhere
Copy link
Member

Testing, I find 3 is resolved by #5333

@radarhere
Copy link
Member

I've created #5338 to change the default behaviour for 1, since I realised that GIF already behaves in this way.

@madeddy
Copy link
Author

madeddy commented Mar 17, 2021

Really great! 🥳
Thanks for your work and getting back to this. (This can then be closed with the successful pull merge.)

Greets

Pillow automation moved this from New Issues to Closed Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Pillow
  
Closed
Development

Successfully merging a pull request may close this issue.

2 participants