django-form-utils
django-form-utils copied to clipboard
ImageWidget depends on having image decoder installed.
In the ImageWidget code, there is a line that checks whether value
is an image:
if hasattr(value, 'width') and hasattr(value, 'height'):
This works great unless you don't have decoders that PIL needs for a specific file type.
For example:
If you store a JPEG image in your model but have no need to process it (no decoder or django-thumbnail-app is installed) then when that line runs PIL will throw and catch an IO error, causing the line to interpret as False
This means it will render only the file upload input and not the image.
I find that to be unexpected behavior if I have no need for image processing.
Yes, this is not ideal. I'm not sure what would be a good way to reliably identify image values that wouldn't suffer from this problem; if you have a proposal (and better, a patch!) I'd welcome it.
Hi, Not quite sure I understand this. Why do we need to access the attribute when is not used?
if hasattr(value, 'width') and hasattr(value, 'height'):
image_html = thumbnail(value.name, self.width, self.height)
We access those attributes simply as a way of determining whether value
is an image or not.
I'm working with django-storages using S3. Apparently, the width/height will always be fetched and is described in this ticket: https://code.djangoproject.com/ticket/8307 . As a result, it has to read the file to get the up to date weight/height and will be slow for cloud based storages.
A similar issue on SO: http://stackoverflow.com/questions/5877497/storing-images-and-thumbnails-on-s3-in-django
Since I'm working on the ImageField, should I override this on my own widget to prevent the extra hit on S3?
I don't know what you should do in that case, I haven't worked with ImageField
and remote storages.
Regarding this specific bug, I'd welcome proposals of an alternative way to reliably tell whether value
is an image that can be (potentially) thumbnailed.
I can take a look next week, but if anyone else wants to take shot?
Sent from my iPhone 4S
On Apr 12, 2013, at 10:26 AM, Carl Meyer [email protected] wrote:
I don't know what you should do in that case, I haven't worked with ImageField and remote storages.
Regarding this specific bug, I'd welcome proposals of an alternative way to reliably tell whether value is an image that can be (potentially) thumbnailed.
— Reply to this email directly or view it on GitHubhttps://github.com/carljm/django-form-utils/issues/2#issuecomment-16299210 .