Created
December 15, 2015 02:12
-
-
Save Andygmb/093db0962e5f7bd39fde to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if size < MIN_PNG_SIZE: | |
raise errors.ClientException('`image` is not a valid image') | |
if size > MAX_IMAGE_SIZE: | |
raise errors.ClientException('`image` is too big. Max: {0} ' | |
'bytes'.format(MAX_IMAGE_SIZE)) | |
first_bytes = image.read(MIN_PNG_SIZE) | |
image.seek(0) | |
if first_bytes.startswith(PNG_HEADER): | |
image_type = 'png' | |
elif first_bytes.startswith(JPEG_HEADER): | |
if size < MIN_JPEG_SIZE: | |
raise errors.ClientException('`image` is not a valid image') | |
image_type = 'jpg' | |
else: | |
raise errors.ClientException('`image` must be either jpg or ' | |
'png.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment