Document loss of palette when converting to NumPy

This commit is contained in:
Andrew Murray 2023-03-31 20:48:14 +11:00
parent f191666a91
commit e95b55acd4

View File

@ -3031,21 +3031,25 @@ def frombuffer(mode, size, data, decoder_name="raw", *args):
def fromarray(obj, mode=None):
"""
Creates an image memory from an object exporting the array interface
(using the buffer protocol).
(using the buffer protocol)::
from PIL import Image
import numpy as np
a = np.zeros((5, 5))
im = Image.fromarray(a)
If ``obj`` is not contiguous, then the ``tobytes`` method is called
and :py:func:`~PIL.Image.frombuffer` is used.
If you have an image in NumPy::
Pillow images can also be converted to arrays::
from PIL import Image
import numpy as np
im = Image.open("hopper.jpg")
a = np.asarray(im)
Then this can be used to convert it to a Pillow image::
im = Image.fromarray(a)
When converting Pillow images to arrays however, only pixel values are
transferred. This means that P and PA mode images will lose their palette.
:param obj: Object with array interface
:param mode: Optional mode to use when reading ``obj``. Will be determined from