镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Resize Error #8220

Closed as not planned
Closed as not planned

Description

@mucmch

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

Activity

  1. radarhere commented on Jul 10, 2024

    @radarhere
    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.

  2. mucmch commented on Jul 10, 2024

    @mucmch
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions