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

Resize Error #8220

Closed
mucmch opened this issue Jul 10, 2024 · 2 comments
Closed

Resize Error #8220

mucmch opened this issue Jul 10, 2024 · 2 comments

Comments

@mucmch
Copy link

mucmch commented Jul 10, 2024

Image resizing errors on Pillow v.10.4.0, while it ran smoothly in older versions (10.3.0, 9.3.0).

Sample Code

from io import BytesIO
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
from PIL.Image import Resampling


def create_test_image():
    file = BytesIO()
    image = Image.new('RGBA', size=(50, 50), color=(155, 0, 0))
    image.save(file, 'png')
    file.name = 'test.png'
    file.seek(0)
    return file


source_file = create_test_image()

fig, ax = plt.subplots()
wm = Image.open(source_file)
wm_size = np.array(wm.size)
max_size = fig.get_size_inches() * fig.dpi * 0.6  # NOQA
scaling_factor = min(max_size / wm_size)

img_size = (wm_size * scaling_factor).astype(int)
wmr = wm.resize(img_size, Resampling.LANCZOS)

Error Log

Traceback (most recent call last):
...
File "...\scratches\scratch.py", line 26, in
wmr = wm.resize(img_size, Resampling.LANCZOS)
File "...\anaconda3\envs\dev\lib\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: Windows 11 Pro / Gitlab Servers
  • Python: 3.10.8
  • Pillow: 10.4.0
@radarhere
Copy link
Member

Hi. This is a duplicate of #8195

We weren't testing for users who used NumPy and resize() in this way. The next version of Pillow will have that functionality again, thanks to #8201.

In the meantime, wm.resize(tuple(img_size), Resampling.LANCZOS) should fix your problem.

@mucmch
Copy link
Author

mucmch commented Jul 10, 2024

Thanks for the quick feedback and sorry for the duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants