Skip to content

Error converting APNG to WEBP #7015

@sjbitcode

Description

@sjbitcode

What did you do?

Opened an animated png file and tried saving it as a webp image.

I tried two animated png's:

What did you expect to happen?

I expected the webp versions to successfully save the animations for both images.

What actually happened?

Error from WebPImagePlugin.py on save:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sangeeta/Code/python-pillow-practice/venv/lib/python3.10/site-packages/PIL/Image.py", line 2431, in save
    save_handler(self, fp, filename)
  File "/Users/sangeeta/Code/python-pillow-practice/venv/lib/python3.10/site-packages/PIL/WebPImagePlugin.py", line 287, in _save_all
    enc.add(
TypeError: 'float' object cannot be interpreted as an integer

What are your OS, Python and Pillow versions?

  • OS: macOS Monterey v12.5
  • Python: 3.10.2
  • Pillow: 9.4.0
from PIL import Image

# walking man apng
img = Image.open('img/man.png')
print(img.format)
print(img.mode)
print(img.get_format_mimetype())
print(img.info)
img.save('transformed/man.webp', save_all=True)


# beach ball apng
img2 = Image.open('img/beach_ball.png')
print(img2.format)
print(img2.mode)
print(img2.get_format_mimetype())
print(img2.info)
img2.save('transformed/beach_ball.webp', save_all=True)

The output:

>>> img = Image.open('img/man.png')
>>> print(img.format)
PNG
>>> print(img.mode)
RGB
>>> print(img.get_format_mimetype())
image/apng
>>> print(img.info)
{'loop': 0, 'transparency': (0, 0, 16), 'bbox': (0, 0, 1400, 1050), 'duration': 41.666666666666664, 'disposal': 0, 'blend': 0}
>>> img.save('transformed/man.webp', save_all=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sangeeta/Code/python-pillow-practice/venv/lib/python3.10/site-packages/PIL/Image.py", line 2431, in save
    save_handler(self, fp, filename)
  File "/Users/sangeeta/Code/python-pillow-practice/venv/lib/python3.10/site-packages/PIL/WebPImagePlugin.py", line 287, in _save_all
    enc.add(
TypeError: 'float' object cannot be interpreted as an integer


>>> img2 = Image.open('img/beach_ball.png')
>>> print(img2.format)
PNG
>>> print(img2.mode)
RGBA
>>> print(img2.get_format_mimetype())
image/apng
>>> print(img2.info)
{'loop': 0, 'bbox': (0, 0, 100, 100), 'duration': 75.0, 'disposal': 1, 'blend': 0}
>>> img2.save('transformed/beach_ball.webp', save_all=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sangeeta/Code/python-pillow-practice/venv/lib/python3.10/site-packages/PIL/Image.py", line 2431, in save
    save_handler(self, fp, filename)
  File "/Users/sangeeta/Code/python-pillow-practice/venv/lib/python3.10/site-packages/PIL/WebPImagePlugin.py", line 287, in _save_all
    enc.add(
TypeError: 'float' object cannot be interpreted as an integer

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions