Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageWidget depends on having image decoder installed. #2

Open
thekashifmalik opened this issue Mar 5, 2013 · 6 comments
Open

ImageWidget depends on having image decoder installed. #2

thekashifmalik opened this issue Mar 5, 2013 · 6 comments

Comments

@thekashifmalik
Copy link

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.

@carljm
Copy link
Owner

carljm commented Mar 7, 2013

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.

@tsailiming
Copy link

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)

@carljm
Copy link
Owner

carljm commented Apr 12, 2013

We access those attributes simply as a way of determining whether value is an image or not.

@tsailiming
Copy link

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?

@carljm
Copy link
Owner

carljm commented Apr 12, 2013

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.

@thekashifmalik
Copy link
Author

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//issues/2#issuecomment-16299210
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants