Skip to content

Conversation

@ViktorSky
Copy link
Contributor

Updating stubs for the PIL.ImageSequence module

This module is used to extract the frames from an Image object, but currently it gives a type error for not having annotation.
In version 10.2.0 pillow is already included with annotations for this module, but it is hidden by _typesheed

here I leave the reason for the pull

from typing import BinaryIO
from PIL import Image, ImageSequence
from io import BytesIO

def resize_gif(file: str | BinaryIO, size: tuple[int, int], mode: str | None = None) -> BytesIO:
    gif = Image.open(file)
    frames: list[Image.Image] = []
    for frame in ImageSequence.all_frames(gif):
        if mode:
            frame = frame.convert(mode)
        frames.append(frame.resize(size))
    image, *frames = frames
    result = BytesIO()
    image.save(result, save_all=True, append_images=frames, duration=gif.info["duration"], loop=gif.info["loop"])
    return result

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@srittau srittau merged commit f337eb8 into python:main Mar 23, 2024
@ViktorSky ViktorSky deleted the patch-1 branch March 26, 2024 02:42
@ViktorSky ViktorSky restored the patch-1 branch March 26, 2024 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants