title: How to resize the new uploaded images using PIL before saving?
body: <p>I want to resize the new images in a height and width of 800px and save them. And the app mustn't store the real image. Any help?</p>
  
  <p>This is my code, it saves the original image and don't the resized photo:</p>
  
  <p>models.py:</p>
  
  <pre><code>class Photo(models.Model):        
      photo = models.ImageField(upload_to='photos/default/')
  
  
      def save(self):
  
          if not self.id and not self.photo:
              return            
  
          super(Photo, self).save()
  
          image = Image.open(self.photo)
          (width, height) = image.size
  
          "Max width and height 800"        
          if (800 / width &lt; 800 / height):
              factor = 800 / height
          else:
              factor = 800 / width
  
          size = ( width / factor, height / factor)
          image.resize(size, Image.ANTIALIAS)
          image.save(self.photo.path)
  </code></pre>