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

Added ImageSequence all_frames #3778

Merged
merged 3 commits into from Jun 29, 2019
Merged

Conversation

radarhere
Copy link
Member

Resolves #3758

Adds a new method to apply a supplied function to all frames of an image at once. So, for example,

from PIL import Image, ImageSequence
im = Image.open('Tests/images/g4-multi.tiff')

ims = ImageSequence.all_frames(im, lambda im_frame: im_frame.rotate(180))

ims[0].save('out.tiff', save_all=True, append_images=ims[1:])

@pirate486743186
Copy link
Contributor

hmmm.... Maybe add multi-threading support?
The function could take a third parameter, the maximum number of threads to be used, default to one.

If no time for this, then you could just silently add the third parameter anyway, so that future code is backwards compatible with the first version of the function.

@radarhere
Copy link
Member Author

While we are concerned with backwards compatibility, I don't think that we are concerned with forwards compatibility.

Nothing else in the Pillow runtime uses multiprocessing, so I'm not personally inclined to integrate it here. If anyone else feels otherwise, feel free to comment. Multiprocessing can't be applied to the process of splitting up a single image into frames, because it uses the same file pointer, but it could be applied to the supplied function. If a user wanted to do that, they could just -

from PIL import Image, ImageSequence
im = Image.open('Tests/images/iss634.gif')

ims = ImageSequence.all_frames(im)

from multiprocessing import Pool
def f(im_frame):
    return im_frame.rotate(180)
ims = Pool(5).map(f, ims)

ims[0].save('out.gif', save_all=True, append_images=ims[1:])

@pirate486743186
Copy link
Contributor

pirate486743186 commented Apr 8, 2019

but isn't this a special case? You are basically processing multiple images at once. And it seems it would be used frequently IMHO.

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

Please add release notes.

docs/releasenotes/6.1.0.rst Outdated Show resolved Hide resolved
Co-Authored-By: Hugo <hugovk@users.noreply.github.com>
@hugovk hugovk self-requested a review June 29, 2019 08:03
@radarhere radarhere merged commit 9074eda into python-pillow:master Jun 29, 2019
@radarhere radarhere deleted the all_frames branch June 29, 2019 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transforms and enhancements across all frames
3 participants