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
Throw error on incorrect type in Image.putpixel #4876
Comments
Hi. I'm not seeing this on my machine. Could you provide code so that we have an exact example, and let us know what version of Pillow you are using? import PIL
print(PIL.__version__)
from PIL import Image
im = Image.new("L", (1, 1))
im.putpixel("test", 0) gives me
Trying with a tuple instead, import PIL
print(PIL.__version__)
from PIL import Image
im = Image.new("L", (1, 1))
im.putpixel(("test", "test"), 0) I get
|
Based on the SO answer, I found I can reproduce the given error message with Line 560 in 8deaebd
|
@radarhere, I got the error because I was mapping my data from for y in range(height):
for x in range(width):
img.putpixel((x,y), map_[x,y]) My @nulano, I proposed catching the error in the Python code, because that's what I know, but yes, it might make more sense to correct it in the C code. If that's the case, someone else can add the fix, because my C knowledge is limited. |
I have created PR #4882 to fix this in C. |
This text is pasted from my PR, #4875
For
Image
objects with modeL
(greyscale), when runningimg.putpixel
, if the argumentxy
is not a tuple with types (int, int), the code raises a rather cryptic error:Again, if the argument is a tuple, but not with the types
(int, int)
, this error will come up, which is likely to confuse many people. I propose adding anif
statement in theputpixel
function to catch this case, and then to throw a clearer error message:Where
xy
is replaced by whatever acutal value ofxy
caused the error.See the Pull Request.
The text was updated successfully, but these errors were encountered: