If the image verifies, and is on your server already, why not resize it? :D On Thu, Jul 3, 2008 at 11:49 PM, Berco Beute <[EMAIL PROTECTED]> wrote:
> > To answer my own question, I now moved the validation code to the form > and create a PIL image using > Image.open(StringIO(uploadedFile.content)): > > ===forms.py > > class ImageForm(forms.ModelForm): > > def __init__(self, *args, **kwargs): > super(ImageForm, self).__init__(*args, **kwargs) > > def clean_image(self): > uploadedFile = self.cleaned_data['image'] > if uploadedFile: > from PIL import Image > from cStringIO import StringIO > try: > image = Image.open(StringIO(uploadedFile.content)) > image.load() > image.verify() > if (image.size[0] > maxImgWidth) or (image.size[1] > > maxImgHeight): > raise > return self.cleaned_data['image'] > except: > raise forms.ValidationError('Image is too big.') > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---