I've got a python Image object from a screen capture that I want to save on a server running PHP.
I want to do all of this without at all saving the image on the user's computer, so I want to send the PHP script an encoding it can understand which I can get from the PIL Image instance.
So far, I've tried saving the Image to a buffer (in python) and sending the data to the PHP function file_put_contents, but the resulting file isn't a correct .png image (I've just saved the PNG encoding string to a file with a .png extension...)
Here's my code...
Client
# shot is an Image instance
buff = StringIO()
shot.save(buff, 'PNG')
args = {'filename':'eg.png','image': buff.getValue()}
data = urllib.urlencode(args)
request = urllib2.Request(self.uploadURL, data)
urllib2.urlopen(request).read()
Server
# 'filename' arg ends in .png, 'image' arg is the upload parameter ^
$filename = 'images/'.$_POST['filename'];
file_put_contents($filename, $_POST['image']);
I take it I need to convert the image data with PHP before I try to write it to file, but I'm not sure how.
I've done this before by saving the Image to file and sending the binary content in base 64, but I don't wish to save the Image on the client's computer at all.
Thanks!
Disclaimer: This question and my perception on encoding feels entirely 'icky' to me, so sorry for being such a huge noob / horrible misunderstanding.