#24441: core.files.images.get_image_dimensions broken
------------------------------+----------------------------------------
     Reporter:  artscoop      |      Owner:  nobody
         Type:  Bug           |     Status:  new
    Component:  Core (Other)  |    Version:  1.7
     Severity:  Normal        |   Keywords:  imagefield, imagefilefield
 Triage Stage:  Unreviewed    |  Has patch:  0
Easy pickings:  0             |      UI/UX:  0
------------------------------+----------------------------------------
 Each time you access a model instance which contains an `ImageField`,
 `core.files.images.get_image_dimensions` is called. I have always found it
 overkill but whatever.
 The bug is that the function chokes because `get_image_dimensions` returns
 `None` on a valid image (which is a 1x1 BMP32ARGB, not recognized by
 Pillow).
 I end with a
 {{{
 >> return self._get_image_dimensions()[0]
 TypeError: 'NoneType' object has no attribute '__getitem__'
 }}}

 When hitting an unrecognized image file, the function should still return
 a tuple like `(0, 0)` or (-1, -1). I changed the function code to this:
 {{{
     from PIL import Image
     try:
         image = Image.open(file_or_path)
         return image.size  # raster data is not loaded here
     except IOError:
         return [-1, -1]
 }}}
 what do you think ? It appears as a bug to me.

--
Ticket URL: <https://code.djangoproject.com/ticket/24441>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.d1d137c41aaa150967142e24e014d11b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to