#24441: core.files.images.get_image_dimensions broken
-------------------------------------+-------------------------------------
     Reporter:  artscoop             |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Core (Other)         |                  Version:  1.7
     Severity:  Normal               |               Resolution:
     Keywords:  imagefield,          |             Triage Stage:
  imagefilefield                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by artscoop):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Old description:

> 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.

New description:

 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)` (but it returns `None`). 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#comment:1>
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/066.8fe5dec3204197a6e7b7142fe49eabb8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to