I'm working on a photo editor program on python called Photo Editor Max.But I've came across a problem. I need to be able to get the data off of the python canvas and transfer it into a png so that I can save images that people are creating. Now I was reading through some things in the internet trying to find a way on how to convert python canvas into a png file. And I've came across two solutions on how to do it. But I'm not too sure how to get some data for some of it's processes and how it works. So the first solution was: To get an RGB Array from python canvas then use the following code which I can implement into my program to save the image
from PIL import Image
newimage = Image.new('RGB', (len(rgbArray[0]), len(rgbArray))) # type, size
newimage.putdata([tuple(p) for row in rgbArray for p in row])
newimage.save("filename.png") # takes type from filename extension
The variable rgbArray is the RGB array that I've taken from the canvas. But I'm not too sure on how to achieve the data for this array. (Which will be like a string of values in brackets. Check : Convert an integer array to a PNG image in Python to know what I'm on about )
Now my second solution is to convert the things in the python canvas into bit64. Then maybe try to use that data to convert it into a png which is able to be saved. Example code :
canvas = document.getElementById("canvas"),
dataURL = canvas.toDataURL();
So please may I have some help with my problem? It'll do me wonders if you can help!