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 explanation of fromarray "mode" parameter #5849

Merged
merged 1 commit into from
Nov 23, 2021
Merged
Changes from all 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
19 changes: 16 additions & 3 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2773,16 +2773,29 @@ def fromarray(obj, mode=None):

from PIL import Image
import numpy as np
im = Image.open('hopper.jpg')
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)

:param obj: Object with array interface
:param mode: Mode to use (will be determined from type if None)
See: :ref:`concept-modes`.
:param mode: Optional mode to use when reading ``obj``. Will be determined from
type if ``None``.

This will not be used to convert the data after reading, but will be used to
change how the data is read::

from PIL import Image
import numpy as np
a = np.full((1, 1), 300)
im = Image.fromarray(a, mode="L")
im.getpixel((0, 0)) # 44
im = Image.fromarray(a, mode="RGB")
im.getpixel((0, 0)) # (44, 1, 0)

See: :ref:`concept-modes` for general information about modes.
:returns: An image object.

.. versionadded:: 1.1.6
Expand Down