title: Get Binary Representation of PIL Image Without Saving
body: <p>I am writing an application that uses images intensively. It is composed of two parts. The client part is written in Python. It does some preprocessing on images and sends them over TCP to a Node.js server. 
  After preprocessing, the Image object looks like this: </p>
  
  <pre><code>window = img.crop((x,y,width+x,height+y))
  window = window.resize((48,48),Image.ANTIALIAS)
  </code></pre>
  
  <p>To send that over socket, I have to have it in binary format. What I am doing now is: </p>
  
  <pre><code>window.save("window.jpg")
  infile = open("window.jpg","rb")
  encodedWindow = base64.b64encode(infile.read())
  #Then send encodedWindow 
  </code></pre>
  
  <p>This is a huge overhead, though, since I am saving the image to the hard disk first, then loading it again to obtain the binary format. This is causing my application to be extremely slow. 
  I read the documentation of PIL Image, but found nothing useful there. </p>