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
UnboundLocalError: local variable 'err_code' referenced before assignment #2383
Comments
Thanks, a couple of people have reported this, but your report is the first to include a triggering image. |
No problem, I might wanna also include that the gif was processed before (loaded into PIL, frames extracted, Wand/Imagemagick effects applied and then stitched together with ffmpeg) using the same function. |
This URL gives me: <?xml version='1.0' encoding='UTF-8'?><Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message></Error> Please could you attach the image to this issue? |
The basic problem is that the second frame has an extent of 256x249, while the first frame is 256x248.
This is in a try/except, which simply swallows the error. for decoder_name, extents, offset, args in self.tile:
decoder = Image._getdecoder(self.mode, decoder_name,
args, self.decoderconfig)
seek(offset)
try:
decoder.setimage(self.im, extents)
except ValueError:
continue Which bounces out, and then we hit the I know that in other image types (e.g., TIFF) when we have multiple frames, we allow for the new image to be a different size than the old one. TIFFs don't have disposal options that GIFs have, so there's a little more complication in the GIF case. I'd propose that if the extents are outside the existing image, we should increase the canvas size to cover the union of the existing and next frame. (as long as the extents aren't negative. I think that we should bounce that error). Additionally, we should not bury errors of this sort. They should probably be raised and allowed to stop the processing. |
Ah, well that makes more sense now. Increasing canvas size does sound like a good way to go unless there are other complications, thanks again! |
Negative extents aren't actually possible, as the offsets are unsigned integers. Pillow/src/PIL/GifImagePlugin.py Line 234 in c47792c
Lines 32 to 34 in c47792c
I've created PR #3822 to resolve this. |
What did you do?
Load a GIF and attempted to save each frame to a file
What did you expect to happen?
Each frame of the gif is saved to a different image file in a directory
What actually happened?
The loop errored before completion
What versions of Pillow and Python are you using?
Latest PIL from PyPy, Python 3.6
Replicated just using PIL from repl.
GIF In question: https://cdn.discordapp.com/attachments/272432272949510144/275311320017010709/gmagik.gif (can give more samples if needed)
The text was updated successfully, but these errors were encountered: