As a result of the discussion below I tried to find the documentation for 'django.core.files.images.get_image_dimensions'
I can't find it in the official documentation. Here: http://www.djangoproject.com/documentation/ nor here: http://docs.djangoproject.com Of course I can find it *some*where on the inter webs, but shouldn't it be in the official documentation? It was the reason I was overlooking an elegant solution to my problem. The reason I'm posting this is that I'm not used to not finding something in the Django docs. They are usually of extraordinary good quality. 2B On Aug 28, 12:13 am, Berco Beute <[EMAIL PROTECTED]> wrote: > Thanks, that works great! I didn't know about 'from > django.core.files.images import get_image_dimensions'. Where can I > find documentation about that? I've tried a custom 'clean_image' > before using PIL, but that was just plain ugly. I never knew about > 'get_image_dimensions'. > > 2B > > > It's much simpler (and more appropriate) to do this in your form > > itself. Specifically, add a clean_image method to your form and check > > the image dimensions there. Then raise a forms.ValidationError on the > > appropriate condition. Something along these lines would be a start: > > > def clean_image(self): > > from django.core.files.images import get_image_dimensions > > image = self.cleaned_data['image'] > > w, h = get_image_dimensions(image) > > if w > 640: > > raise forms.ValidationError(u'That image is too wide.') > > return image > > > -Rajesh D --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

