title: Exception Type: OSError Exception Value: cannot write mode RGBA as JPEG
body: <p>I have upload more than 10 images with the help of the following code in my django application(using image pillow library).</p>
  
  <pre><code>def save(self):
      im = Image.open(self.image)
      output = BytesIO()
      im = im.resize((500, 500))
  
      im.save(output, format='JPEG', optimize=True, quality=95)
      output.seek(0)
  
      self.image = InMemoryUploadedFile(output, 'ImageField', "%s.jpg" % self.image.name.split('.')[0], 'image/jpeg',
                                        sys.getsizeof(output), None)
  
      super(Report_item, self).save()
  </code></pre>
  
  <p>But now my Django application is giving me following error.</p>
  
  <pre><code>Exception Type: OSError
  Exception Value:    
  cannot write mode RGBA as JPEG
  </code></pre>
  
  <p>I got the solution from one of the answers at StackOverflow to change the image type to from any other to png.</p>
  
  <p>Now my code looks like this but the process seems a bit slow as compared to it was earlier.</p>
  
  <pre><code>def save(self):
      im = Image.open(self.image)
      output = BytesIO()
      im = im.resize((500, 500))
  
      im.save(output, format='PNG', optimize=True, quality=95)
      output.seek(0)
  
      self.image = InMemoryUploadedFile(output, 'ImageField', "%s.png" % self.image.name.split('.')[0], 'image/jpeg',
                                        sys.getsizeof(output), None)
  
      super(Report_item, self).save()
  </code></pre>
  
  <p>Now the image is uploading without any issue. </p>
  
  <p>Please explain to me why I got that error after uploading more than 10 pics. 
  Is this the right way to do so. What if I want to save in jpeg format? 
  My application is in production. So I want to push only the right code for the right job. Please help me to figure out.</p>