I am writing an application that makes heavy use of images. It consists of two parts. The client part is written in Python. It does some image preprocessing and sends them over TCP to the Node.js server. After preprocessing, the Image object looks like this:
window = img.crop((x,y,width+x,height+y))
window = window.resize((48,48),Image.ANTIALIAS)
To send this socket, I have to have it in binary format. Now I am doing the following:
window.save("window.jpg")
infile = open("window.jpg","rb")
encodedWindow = base64.b64encode(infile.read())
This is a huge overhead, however, since I first save the image to my hard drive and then upload it again to get the binary format. This causes my application to run very slowly. I read the PIL Image documentation but found nothing useful there.
source
share