Skip to content

apng duration returns float instead of int #9358

@CTimmerman

Description

@CTimmerman

What did you do?

Get the duration of an apng file.

What did you expect to happen?

Get the ms as int. As documented, setting requires an int.

What actually happened?

Got ms as float.

What are your OS, Python and Pillow versions?

  • OS: Windows 11 Home 24H2
  • Python: Python 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)] on win32
  • Pillow: 12.0.0
--------------------------------------------------------------------
Pillow 12.0.0
Python 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)]
--------------------------------------------------------------------
Python executable is D:\code\image viewer\tk_image_viewer\venv\Scripts\python.exe
Environment Python files loaded from D:\code\image viewer\tk_image_viewer\venv
System Python files loaded from C:\Users\C\AppData\Local\Python\pythoncore-3.13-64
--------------------------------------------------------------------
Python Pillow modules loaded from D:\code\image viewer\tk_image_viewer\venv\Lib\site-packages\PIL
Binary Pillow modules loaded from D:\code\image viewer\tk_image_viewer\venv\Lib\site-packages\PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 12.0.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.14.1
--- LITTLECMS2 support ok, loaded 2.17
--- WEBP support ok, loaded 1.6.0
--- AVIF support ok, loaded 1.3.0
--- JPEG support ok, compiled for libjpeg-turbo 3.1.2
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.4
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1.zlib-ng, compiled for zlib-ng 2.2.5
--- LIBTIFF support ok, loaded 4.7.1
--- RAQM (Bidirectional Text) support ok, loaded 0.10.3, fribidi 1.0.13, harfbuzz 12.1.0
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
--------------------------------------------------------------------
from PIL import GifImagePlugin, Image, ImageGrab, ImageTk

im = Image.open(path)
im.load()  # Else im.info = {} for AVIF.
if hasattr(im, "n_frames"):
    n = im.n_frames
    if n > 1:
        APP.info["Frames"] = n
        duration: int = 0
        # for frame in range(n - 1, -1, -1):  # 116 GIF frames in 15.45s vs 0.21s!
        for frame in range(n):
            im.seek(frame)
            duration += im.info.get("duration", 100) or 100
        im.seek(0)
        print(duration)  # should be an int as Tk's `after()` expects

anim-icos.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions