Skip to content

Let Image.fromarray infer mode for 2D float32 thumbnail arrays for Pillow >= 13 compatibility. - #11256

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_1018508067
Nov 11, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_1018508067

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Let Image.fromarray infer mode for 2D float32 thumbnail arrays for Pillow >= 13 compatibility.

Pillow 13.0.0 redeprecates the mode parameter in Image.fromarray and raises ValueError: Invalid mode for data type when mode='L' is passed with a 2D np.float32 array. In create_thumbnail, 1-channel np.float32 images squeezed to 2D previously fell into the else: mode = 'L' branch.

Handle np.float32 alongside np.uint16 for 1-channel images by passing mode=None (which infers 'F' for 2D float32 arrays) and converting to 'RGB' via _postprocess_convert_rgb before saving the PNG thumbnail.

…llow >= 13 compatibility.

Pillow 13.0.0 [redeprecates](https://pillow.readthedocs.io/en/latest/releasenotes/13.0.0.html#image-fromarray-mode-parameter) the `mode` parameter in `Image.fromarray` and raises `ValueError: Invalid mode for data type` when `mode='L'` is passed with a 2D `np.float32` array. In `create_thumbnail`, 1-channel `np.float32` images squeezed to 2D previously fell into the `else: mode = 'L'` branch.

Handle `np.float32` alongside `np.uint16` for 1-channel images by passing `mode=None` (which infers `'F'` for 2D `float32` arrays) and converting to `'RGB'` via `_postprocess_convert_rgb` before saving the PNG thumbnail.

PiperOrigin-RevId: 1019097631
@copybara-service copybara-service Bot closed this Nov 11, 2026
@copybara-service
copybara-service Bot deleted the test_1018508067 branch November 11, 2026 13:17
@copybara-service
copybara-service Bot merged commit a96809c into master Nov 11, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant