Skip to content

Commit

Permalink
feat: validate template header logo image format
Browse files Browse the repository at this point in the history
  • Loading branch information
tmszi committed Apr 21, 2020
1 parent 2d586b2 commit 4cc3ef5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions apps/html_template_editor/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
def validate_logo_image(image):
max_width = 300
megabyte_limit = 5.0 * 1024 * 1024
allowed_image_formats = ['JPEG', 'PNG']

width, height = Image.open(image).size
img = Image.open(image)
width, height = img.size
image_file_size = image.tell()
image_file_format = img.format

if image_file_format not in allowed_image_formats:
raise ValidationError(
_("Allowed image format is %(image_formats)s "),
params={'image_formats': ', '.join(allowed_image_formats)},
)

print(width, image_file_size)
if width > max_width:
raise ValidationError(
_("Width is larger than what is allowed %(max_width)s px"),
Expand Down

0 comments on commit 4cc3ef5

Please sign in to comment.