title: Python: How to read images from zip file in memory?
body: <p>I have seen variations of this question, but not in this exact context. What I have is a file called 100-Test.zip which contains 100 .jpg images. I want to open this file in memory and process each file doing PIL operations. The rest of the code is already written, I just want to concentrate on getting from the zip file to the first PIL image. This is what the code looks like now from suggestions I've gathered from reading other questions, but it's not working. Can you guys take a look and help? </p>
  
  <pre><code>import zipfile
  from StringIO import StringIO
  from PIL import Image
  
  imgzip = open('100-Test.zip', 'rb')
  z = zipfile.ZipFile(imgzip)
  data = z.read(z.namelist()[0])
  dataEnc = StringIO(data)
  img = Image.open(dataEnc)
  
  print img
  </code></pre>
  
  <p>But I am getting this error when I run it:</p>
  
  <pre><code> IOError: cannot identify image file &lt;StringIO.StringIO instance at
   0x7f606ecffab8&gt;
  </code></pre>
  
  <p>Alternatives: I have seen other sources saying to use this instead: </p>
  
  <pre><code>image_file = StringIO(open("test.jpg",'rb').read())
  im = Image.open(image_file)
  </code></pre>
  
  <p>But the problem is I'm not opening a file, it's already in memory inside the data variable. I also tried using <code>dataEnc = StringIO.read(data)</code> but got this error:</p>
  
  <pre><code>TypeError: unbound method read() must be called with StringIO instance as 
  first argument (got str instance instead)
  </code></pre>