Skip to content

Instantly share code, notes, and snippets.

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