-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
IndexError while drawing on an image #1987
Comments
So, there are at least three problems here. Edit -- no, not this, there are just a bunch of null bytes at the end, and they're probably just extra unused colors.
Edit -- no, the palette is set 'correctly' image.im.getpalette, but image.palette is not right.
additional edits: There's some severe disconnect between the lower level palette information and the python level palettes. I don't see where the python colors dict is ever populated, so when draw happens on a newly loaded image, there are no colors loaded, so it starts overwriting at the first one. The palette at that point may be scrambled if it's come from a raw palette, and would be in the RGB mode instead of RGB;L. It's possible that on load we want to take the palette from the c layer and bring it back up to the python layer, but we'd probably want to know how long it is to prepopulate the colors dictionary. |
f7d8466 This fixes the IndexError. The palette is still screwed up though. |
The image is in P mode. Should the |
I fixed the error by converting the image with 'P' mode into 'RGB' mode. Check the following link to convert the mode: |
Trying again after #5552, I find that I just need to from PIL import Image, ImageDraw
def deborder(filename):
frame = Image.open(filename)
frameNo = 0
frames = []
while True:
try:
frame.seek(frameNo)
except EOFError:
break
image = frame.copy()
draw = ImageDraw.Draw(image)
topLeft = (0, 0)
topRight = (frame.size[0] - 1, 0)
bottomLeft = (0, frame.size[1] - 1)
bottomRight = (frame.size[0] - 1, frame.size[1] - 1)
draw.line((topLeft, topRight), fill=(255, 255, 255))
draw.line((topLeft, bottomLeft), fill=(255, 255, 255))
draw.line((bottomLeft, bottomRight), fill=(255, 255, 255))
draw.line((topRight, bottomRight), fill=(255, 255, 255))
frameNo += 1
frames.append(image)
frames[0].save('resave-'+filename, save_all=True, append_images=frames[1:])
deborder('no.gif') |
With Pillow 3.2.0 on Python 3 (and on Python 2, with the fix in #1985), running the very same code as in #1592 with the very same image slightly edited, the following traceback occurs:
Before the #1985 fix, the error is an
IndexError: list assignment index out of range
. After, it persists as anIndexError: bytearray index out of range
, however.From what I can tell, self.palette is shorter than 256 elements, and can therefore not take an assignment to index
index+256
. In this case, index is 0, aslen(self.colors)
ingetcolor
for this image is 0, which I find a bit odd.Since the image is almost exactly the one used in #1592, this may be related. The difference is this one is edited in ImageMagick to make the outer 1px border white (
#FFFFFF
).The very same code as in #1592 causes the error:
With the following image, for example (while the error occurs with the exact image in #1592 edited a bit, I chose one with a different glyph to avoid future confusion):
The text was updated successfully, but these errors were encountered: