Opened 10 years ago
Last modified 10 years ago
#24441 closed Bug
core.files.images.get_image_dimensions broken — at Initial Version
Reported by: | artscoop | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | 1.7 |
Severity: | Normal | Keywords: | imagefield, imagefilefield |
Cc: | andrei kulakov | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
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.