title: How to create an image from a string in python
body: <p>I'm currently having trouble creating an image from a binary string of data in my Python program.  I receive the binary data via a socket but when I try the methods I read about on <a href="http://effbot.org/imagingbook/introduction.htm" rel="noreferrer">here</a> like this:</p>
  
  <pre><code>buff = StringIO.StringIO() #buffer where image is stored
  #Then I concatenate data by doing a 
  buff.write(data) #the data from the socket
  im = Image.open(buff)
  </code></pre>
  
  <p>I get an exception to the effect of "image type not recognized".  I know that I am receiving the data correctly because if I write the image to a file and then open a file it works:</p>
  
  <pre><code>buff = StringIO.StringIO() #buffer where image is stored
  buff.write(data) #data is from the socket
  output = open("tmp.jpg", 'wb')
  output.write(buff)
  output.close()
  im = Image.open("tmp.jpg")
  im.show()
  </code></pre>
  
  <p>I figure I am probably doing something wrong in using the StringIO class but I'm not sure</p>