mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 01:34:24 +03:00
Merge pull request #5773 from radarhere/copy
Improved image lifecycle documentation
This commit is contained in:
commit
174fad7d3d
|
@ -47,6 +47,10 @@ Image Lifecycle
|
||||||
memory. The image can now be used independently of the underlying
|
memory. The image can now be used independently of the underlying
|
||||||
image file.
|
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
|
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
|
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
|
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.seek()`` can load the appropriate frame.
|
||||||
|
|
||||||
* ``Image.Image.close()`` Closes the file and destroys the core image object.
|
* ``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:
|
The Pillow context manager will also close the file, but will not destroy
|
||||||
... # image operations here.
|
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
|
The lifecycle of a single-frame image is relatively simple. The file must
|
||||||
|
|
Loading…
Reference in New Issue
Block a user