Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1.     @staticmethod
  2.     def save_image_png(image):
  3.         miss_pad = len(image) % 4  # add missing padding
  4.  
  5.         if miss_pad != 0:
  6.             image += '=' * (4 - miss_pad)
  7.  
  8.         image = image.split('base64,')[1]
  9.  
  10.         img_data = b64decode(image)
  11.         filename = '%s.png' % hash(image)
  12.         image = ContentFile(img_data, filename)
  13.  
  14.         new_img = DivToPng(image=image)
  15.         new_img.save()
  16.  
  17.         return new_img.image.path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement