from cover.models import Image
from django.utils.safestring import mark_safe
from PIL import Image as PILImage
from cover.models import Image
from django.utils.safestring import mark_safe
from PIL import Image as PILImage
download_url = cleaned_data.get('download_url', None)
uploaded_file = cleaned_data.get('file', None)
if not download_url and not uploaded_file:
download_url = cleaned_data.get('download_url', None)
uploaded_file = cleaned_data.get('file', None)
if not download_url and not uploaded_file:
if download_url:
image_data = URLOpener().open(download_url).read()
width, height = PILImage.open(BytesIO(image_data)).size
if download_url:
image_data = URLOpener().open(download_url).read()
width, height = PILImage.open(BytesIO(image_data)).size
width, height = PILImage.open(uploaded_file.file).size
min_width, min_height = settings.MIN_COVER_SIZE
if width < min_width or height < min_height:
width, height = PILImage.open(uploaded_file.file).size
min_width, min_height = settings.MIN_COVER_SIZE
if width < min_width or height < min_height:
(width, height, min_width, min_height))
return cleaned_data
(width, height, min_width, min_height))
return cleaned_data
width, height = PILImage.open(uploaded_file.file).size
min_width, min_height = settings.MIN_COVER_SIZE
if width < min_width or height < min_height:
width, height = PILImage.open(uploaded_file.file).size
min_width, min_height = settings.MIN_COVER_SIZE
if width < min_width or height < min_height:
(width, height, min_width, min_height))
(width, height, min_width, min_height))