Skip to content

Passing a numpy.ndarray as the size to Image.resize() works in 10.3.0, but not in 10.4.0 #8195

@musicinmybrain

Description

@musicinmybrain

What did you do?

I encountered some new test failures in mikedh/trimesh#2247 because passing a numpy.ndarray as the size to Image.resize() works in 10.3.0, but not in 10.4.0.

The question is whether this is a regression in Pillow, or whether passing a numpy.ndarray to Image.resize() was always “wrong,” since https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize calls for a “tuple,” and it only happened to work.

What did you expect to happen?

With numpy==2.0.0, pillow==10.3.0:

>>> from PIL import Image
>>> from numpy import array
>>> x = Image.new('RGB', (2, 4))
>>> x.resize(array([3, 7]))
<PIL.Image.Image image mode=RGB size=3x7 at 0x7FB58A5866C0>

What actually happened?

With numpy==2.0.0, pillow==10.4.0:

>>> from PIL import Image
>>> from numpy import array
>>> x = Image.new('RGB', (2, 4))
>>> x.resize(array([3, 7]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ben/fedora/neuro-sig/python-trimesh/_e/lib64/python3.12/site-packages/PIL/Image.py", line 2297, in resize
    if self.size == size and box == (0, 0) + self.size:
       ^^^^^^^^^^^^^^^^^
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

What are your OS, Python and Pillow versions?

  • OS: Fedora 40
  • Python: 3.12.3
  • Pillow: 10.4.0 (vs. 10.3.0)

While I originally encountered this building system RPM packages, this report is based on the above reproducer in a clean virtualenv using packages installed from PyPI.

--------------------------------------------------------------------
Pillow 10.4.0
Python 3.12.3 (main, Apr 17 2024, 00:00:00) [GCC 14.0.1 20240411 (Red Hat 14.0.1-0)]
--------------------------------------------------------------------
Python executable is /home/ben/fedora/neuro-sig/python-trimesh/_e/bin/python
Environment Python files loaded from /home/ben/fedora/neuro-sig/python-trimesh/_e
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /home/ben/fedora/neuro-sig/python-trimesh/_e/lib64/python3.12/site-packages/PIL
Binary Pillow modules loaded from /home/ben/fedora/neuro-sig/python-trimesh/_e/lib64/python3.12/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.4.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.4.0
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.3
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.0.zlib-ng
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1, fribidi 1.0.14, harfbuzz 8.5.0
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions