Skip to content
This repository

Fails with PIL on uncomplete exif jpeg #98

Closed
hynekcer opened this Issue April 11, 2012 · 9 comments

6 participants

Hynek Cernoch Mario César Moises Brenes Greg Brown Linus G Thiel Tom Clancy
Hynek Cernoch

Sorl-thumbnail 11 fails in this image file
https://bitbucket.org/chris1610/satchmo/raw/60e0513633ad/satchmo/static/images/productimage-picture-default.jpg
with PIL 1.1.6-3.
because it has empty exif.

Traceback
/home/me/lib/python2.5/sorl/thumbnail/engines/pil_engine.py 29 in _orientation
exif = image._getexif()
/usr/lib/python2.5/site-packages/PIL/JpegImagePlugin.py 354 in _getexif
file.seek(exif[0x8769])
Exception Type: TemplateSyntaxError
Exception Value: Caught KeyError while rendering: 34665

Patch:

diff -u a/sorl/thumbnail/engines/pil_engine.py b/sorl/thumbnail/engines/pil_engine.py
--- a/sorl/thumbnail/engines/pil_engine.py
+++ b/sorl/thumbnail/engines/pil_engine.py
@@ -27,7 +27,7 @@
def _orientation(self, image):
try:
exif = image._getexif()

  • except AttributeError:
  • except AttributeError, KeyError: exif = None if exif: orientation = exif.get(0x0112)
Hynek Cernoch

I am sorry. It should be

except (AttributeError, KeyError):

Deleted user
ghost commented April 18, 2012

The content you are editing has changed. Reload the page and try again.

I'm also getting an IndexError on a png Image with latest PIL v1.1.7. So I guess the except clause should be modified:

except (AttributeError, KeyError, IndexError):

Sending Request…

Attach images by dragging & dropping or selecting them. Octocat-spinner-32 Uploading your images… Unfortunately, we don't support that file type. Try again with a PNG, GIF, or JPG. Yowza, that's a big file. Try again with an image file smaller than 10MB. This browser doesn't support image attachments. We recommend updating to the latest Internet Explorer, Google Chrome, or Firefox. Something went really wrong, and we can't process that image. Try again.

Hynek Cernoch

It looks reasonable. Can you send a link to such png image?

Deleted user
ghost commented April 18, 2012

The content you are editing has changed. Reload the page and try again.

This is the image link (It is in fact a jpg image, not a png)

http://static.punterslobby.com/media/images/news/full/160993.jpg

Can you reproduce this? Simply catching the exception worked for me.

Sending Request…

Attach images by dragging & dropping or selecting them. Octocat-spinner-32 Uploading your images… Unfortunately, we don't support that file type. Try again with a PNG, GIF, or JPG. Yowza, that's a big file. Try again with an image file smaller than 10MB. This browser doesn't support image attachments. We recommend updating to the latest Internet Explorer, Google Chrome, or Firefox. Something went really wrong, and we can't process that image. Try again.

Moises Brenes
gin commented April 26, 2012

I can confirm this issue on sorl-thumbnail version: 11.12 and when I it catches:

except (AttributeError, KeyError, IndexError):

it resolved that issue.

Greg Brown

I'm getting this error too -

except (AttributeError, KeyError, IndexError):

fixed it for me. Definitely needs to be merged into master!

Linus G Thiel

Unfortunately, it seems _getexif() can also give you an IOError.

This image gives me an IOError when calling get_thumbnail (or Image.open('file')._getexif()):

http://apprl.com/media/static/products/mango/1__73650255__73650255_94.jpg

See also http://stackoverflow.com/questions/10583265/python-image-library-error-caught-ioerror-while-rendering-not-enough-data

Marek Wywiał onjin referenced this issue from a commit in onjin/sorl-thumbnail January 27, 2013
Marek Wywiał Fixing #98 and #99 - problems with exif on some images b43e2f6
herrobenny herrobenny referenced this issue from a commit in herrobenny/sorl-thumbnail May 03, 2013
herrobenny fixed #98 and #99 - problems with exif on some images f1f752f
Philip Neustrom philipn referenced this issue from a commit in philipn/sorl-thumbnail June 28, 2013
Philip Neustrom Fix for #98. bdc325a
Tom Clancy

Applying the fix to _getexif() results in an error in get_image()

return Image.open(buf)
File "python2.7/site-packages/PIL/Image.py", line 1980, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file
Reiner Marquez rmaceissoft referenced this issue from a commit in rmaceissoft/sorl-thumbnail October 25, 2013
Reiner Marquez fixed #98 and #99 - problems with exif on some images ebb179a
Mario César mariocesar closed this December 19, 2013
Mario César
Owner

A fix has been merged into the master branch, please reopen this issue if it persists

https://github.com/mariocesar/sorl-thumbnail/blob/master/sorl/thumbnail/engines/pil_engine.py#L65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.