Merge pull request #5773 from radarhere/copy

Improved image lifecycle documentation
This commit is contained in:
Hugo van Kemenade 2021-10-17 09:10:33 +03:00 committed by GitHub
commit 174fad7d3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
@ -55,10 +59,16 @@ 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.::
with Image.open('test.jpg') as img:
... # image operations here.
The Pillow context manager will also close the file, but will not destroy
the core image object. e.g.:
.. code-block:: python
with Image.open("test.jpg") as img:
img.load()
assert img.fp is None
img.save("test.png")
The lifecycle of a single-frame image is relatively simple. The file must