title: Django PIL : IOError Cannot identify image file
body: <p>I'm learning Python and Django.</p>
  
  <p>An image is provided by the user using forms.ImageField(). Then I have to process it in order to create two different sized images.</p>
  
  <p>When I submit the form, Django returns the following error:</p>
  
  <pre><code>IOError at /add_event/
  cannot identify image file
  </code></pre>
  
  <p>I call the resize function:</p>
  
  <pre><code>def create_event(owner_id, name, image):         
      image_thumb = image_resizer(image, name, '_t', 'events', 180, 120)  
      image_medium = image_resizer(image, name, '_m', 'events', 300, 200)
  </code></pre>
  
  <p>I get en error when image_resizer is called for the second time:</p>
  
  <pre><code>def image_resizer(image, name, size, app_name, length, height): 
      im = Image.open(image)
      if im.mode != "RGB":
          im = im.convert("RGB")
      im = create_thumb(im, length, height)
      posit = str(MEDIA_ROOT)+'/'+app_name+'/'
      image_2 = im
      image_name = name + size +'.jpg' 
      imageurl = posit + image_name
      image_2.save(imageurl,'JPEG',quality=80)
      url_image='/'+app_name+'/'+image_name  
      return url_image
  </code></pre>
  
  <p>Versions:<br>
  Django  1.3.1<br>
  Python  2.7.1<br>
  PIL 1.1.7</p>
  
  <p>I'm trying to find the problem, but i don't know what to do. Thank you in advanced!</p>
  
  <p><strong>EDIT</strong><br>
  I solved rewriting the function; now it creates the different images in batch:</p>
  
  <p>I call the resize function:</p>
  
  <pre><code>url_array = image_resizer.resize_batch(image, image_name, [[180,120,'_t'], [300,200,'_m']], '/events/')  
  </code></pre>
  
  <p>so:  </p>
  
  <pre><code>image_thumb = url_array[0]
  image_medium = url_array[1]
  </code></pre>
  
  <p>and the resize function:  </p>
  
  <pre><code>def resize_batch(image, name, size_array, position):
      im = Image.open(image)
      if im.mode != "RGB":
          im = im.convert("RGB")
      url_array = []
      for size in size_array:
          new_im = create_thumb(im, size[0], size[1])
          posit = str(MEDIA_ROOT) + position
          image_name = name + size[2] +'.jpg' 
          imageurl = posit + image_name
          new_im.save(imageurl,'JPEG',quality=90)
          new_url_array = position + image_name
          url_array.append(new_url_array)
      return url_array
  </code></pre>
  
  <p>Thanks to all!</p>