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

Comment (by artscoop):

 Your new title is far more on point, thanks. There are several possible
 choices.

 First choices options:
 - return `(None, None)`. Seems good, but if it's used to populate a
 concrete `width_field` or `height_field`, one must not forget that these
 fields must be nullable.
 - return `(0, 0)`. Good to me too, since no valid image in the world can
 be less than 1x1
 - return `(-1, -1)`. This is a perfectly invalid dimension for any object,
 and it somewhat fits here.

 Second choice:
 Accept `None` as an input, and change **core.files.image.py** from
 {{{
 class ImageFile(File):
     def _get_width(self):
         return self._get_image_dimensions()[0]
     width = property(_get_width)

     def _get_height(self):
         return self._get_image_dimensions()[1]
     height = property(_get_height)
 }}}

 to code which accepts `None` as a dimension:

 {{{
     def _get_width(self):
         width = self._get_image_dimensions()
         return width[0] if width else **invalid value - None, 0 or -1**

     def _get_height(self):
         height = self._get_image_dimensions()
         return height[0] if height else **invalid value - None, 0 or -1**
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24441#comment:6>
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.f628a2e79026ee155e71bef3436d3b25%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to