Skip to content

Instantly share code, notes, and snippets.

@lym
Last active July 15, 2016 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lym/970cbde55b24c7ffab16037420c7f819 to your computer and use it in GitHub Desktop.
Save lym/970cbde55b24c7ffab16037420c7f819 to your computer and use it in GitHub Desktop.
def _check_meter_image(self, meter_image): # meter_image is a base64-encoded string
err_msg = 'Please take a photograph of the meter'
if meter_image:
pre_img = base64.encodestring(bytearray(meter_image, 'utf8'))
pre_img2 = base64.decodestring(pre_img)
img_file = io.BytesIO(pre_img2)
img = Image.open(img_file)
print(img.filename)
if img.format == 'JPEG':
return True
else:
self._log_error(self.errors, err_msg)
else:
self._log_error(self.errors, err_msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment