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

Improved image lifecycle documentation #5773

Merged
merged 3 commits into from
Oct 17, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/reference/open_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Image Lifecycle
memory. The image can now be used independently of the underlying
image file.

Any Pillow method that creates a new image instance based on another will
internally call ``load()`` on the original image and then read the data.
The new image instance will not be associated with the original image file.

If a filename or a ``Path`` object was passed to ``Image.open()``, then the
file object was opened by Pillow and is considered to be used exclusively by
Pillow. So if the image is a single-frame image, the file will be closed in
Expand All @@ -55,10 +59,14 @@ Image Lifecycle
``Image.Image.seek()`` can load the appropriate frame.

* ``Image.Image.close()`` Closes the file and destroys the core image object.
This is used in the Pillow context manager support. e.g.::

The Pillow context manager will also close the file, but will not destroy
the core image object. e.g.::

with Image.open('test.jpg') as img:
radarhere marked this conversation as resolved.
Show resolved Hide resolved
... # image operations here.
img.load()
assert img.fp is None
img.save('test.png')
radarhere marked this conversation as resolved.
Show resolved Hide resolved


The lifecycle of a single-frame image is relatively simple. The file must
Expand Down