I\'m trying to get the contents of an html5 canvas and pass it to my django server, where it will then be manipulated with PIL and saved as a PNG. Here\'s what I have so far
import re
datauri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='
imgstr = re.search(r'base64,(.*)', datauri).group(1)
output = open('output.png', 'wb')
output.write(imgstr.decode('base64'))
output.close()
or if you need to load it into PIL :
import cStringIO
tempimg = cStringIO.StringIO(imgstr.decode('base64'))
im = Image.open(tempimg)