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

SystemError on Image.new / fill for 32-bit mode with color tuple #4925

Closed
bertsky opened this issue Sep 16, 2020 · 3 comments · Fixed by #4927
Closed

SystemError on Image.new / fill for 32-bit mode with color tuple #4925

bertsky opened this issue Sep 16, 2020 · 3 comments · Fixed by #4927

Comments

@bertsky
Copy link

bertsky commented Sep 16, 2020

The following works smoothly:

>>> PIL.Image.new('L', (200,100), (255,)) # accepts tuple

However, for 32-bit modes, this does not work:

>>> PIL.Image.new('F', (200,100), (255,)) # fails okay
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/python3.6/site-packages/PIL/Image.py", line 2613, in new
    return im._new(core.fill(mode, size, color))
TypeError: must be real number, not tuple
>>> PIL.Image.new('I', (200,100), (255,)) # fails badly
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/python3.6/site-packages/PIL/Image.py", line 2613, in new
    return im._new(core.fill(mode, size, color))
SystemError: <built-in function fill> returned NULL without setting an error

At least the error message in the latter case should be improved.

But why not be more tolerant in both cases (I or F), like above (L or P)?

(Seen with Pillow 7.2.0 on Python 3.6.7 Linux x86_64.)

@bertsky
Copy link
Author

bertsky commented Sep 16, 2020

Note: always allowing tuple would make it easier to pass values from ImageStat.Stat().median etc. (without checking for bands and unlisting)

@nulano
Copy link
Contributor

nulano commented Sep 17, 2020

With #4882 in master the last one has a proper error message:

>>> PIL.Image.new('I', (200,100), (255,))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\git\pillow\src\PIL\Image.py", line 2621, in new
    return im._new(core.fill(mode, size, color))
TypeError: color must be int

@radarhere
Copy link
Member

I've created PR #4927 as a suggestion to resolve this.

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 a pull request may close this issue.

3 participants