- if not cleaned_data.get('download_url', None) and not cleaned_data.get('file', None):
- raise forms.ValidationError('No image specified')
+ download_url = cleaned_data.get('download_url', None)
+ uploaded_file = cleaned_data.get('file', None)
+ if not download_url and not uploaded_file:
+ raise forms.ValidationError(ugettext('No image specified'))
+ if download_url:
+ image_data = URLOpener().open(download_url).read()
+ width, height = PILImage.open(StringIO(image_data)).size
+ else:
+ width, height = PILImage.open(uploaded_file.file).size
+ min_width, min_height = settings.MIN_COVER_SIZE
+ if width < min_width or height < min_height:
+ raise forms.ValidationError(ugettext('Image too small: %sx%s, minimal dimensions %sx%s') %
+ (width, height, min_width, min_height))