Skip to content

Instantly share code, notes, and snippets.

@Andygmb
Created December 15, 2015 02:12
Show Gist options
  • Save Andygmb/093db0962e5f7bd39fde to your computer and use it in GitHub Desktop.
Save Andygmb/093db0962e5f7bd39fde to your computer and use it in GitHub Desktop.
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