1

I made a simple conversion method as following:

from PIL import Image

def convert(src, dst):
    with Image.open(src) as img:
        print(f'file opened = {src}')
        if hasattr(img, 'is_animated') and img.is_animated:
            print(f'frames = {img.n_frames}')
            img.save(dst,
                quality=90,
                save_all=True)
        else:
            print('not animated')
            img.save(dst, quality=90)

if __name__ == '__main__':
    convert('src.gif','dst.webp')

I converted some .gif images to animated webp, and there are noises on images.


Results:

results


What am I missing?

I am using Python 3.9.7 Pillow 8.3.2.


source1:

source1

source2:

source2

Alex Waygood
  • 6,304
  • 3
  • 24
  • 46
Eby
  • 43
  • 1
  • 6
  • 1
    some tools are not ideal and you may need to wait for newer version – furas Sep 25 '21 at 15:25
  • I tested your code with animated gif https://i.stack.imgur.com/VJwUH.gif in my answer on https://stackoverflow.com/questions/69253076/problem-with-the-smoothness-of-the-flys-movement/69270625#69270625 and it creates correct `webp`. Maybe it can't work with some gifs. I used [OBS](https://obsproject.com/) to record video and [ffmpeg](https://ffmpeg.org/) to converted video to animate gif. – furas Sep 25 '21 at 16:50
  • I tested your code with your images and `Happy Birthday` gives correct `webp` but `Marry Christmas` gives noises. I used program `file` on Linux to get information about images and it shows that `Marry Christmas` is `gif version 87a` but `Happy Birthday` and my image are `gif version 89a`. Maybe this makes problems. – furas Sep 25 '21 at 17:00
  • if I use `ffmpeg` to (re)convert `Marry Christmas` then I get `gif version 89a` and then your code creates correct `webp`. – furas Sep 25 '21 at 17:03
  • first I tested with Python 3.8 and Pillow 8.2.0 - and it works correctly for `Happy Birthday`. Next I updated to Pillow 8.3.2 and it gives wrong background for `Happy Birthday`. It seems problem is that background in original file is transparent. – furas Sep 25 '21 at 17:17
  • I get correct webp when I use program [gif2web](https://developers.google.com/speed/webp/docs/gif2webp) from [Google's tools for webp](https://developers.google.com/speed/webp). You could use it with Python using `subprocess.run(...)` or `os.system(...)` – furas Sep 25 '21 at 17:27
  • 1
    @furas thank you for answers. i understood i did not set background for `Happy Birthday` you said. Also i noticed the difference of versions of two gif files might be the problem. I tested another tools, phtoscape, photoshop and gif2webp with above two files. And i could get good frames without any problems. So i think `pillow` may have a problem. I tried pillow 8.2.0, still got noised frames. – Eby Sep 27 '21 at 06:30
  • 1
    It fixed in the latest version. – Eby Jan 09 '22 at 06:32

0 Answers0