Reputation: 671
I have the following Django model with overriden save method:
class Photo(models.Model):
image = models.ImageField(upload_to=get_file_path, blank=False, null=False)
def save(self, *args, **kwargs):
"""
Override save method to resize uploaded photo images to max_size.
"""
if not self.id and not self.image:
return
super(Photo, self).save(*args, **kwargs)
resized_image = Image.open(self.image)
resized_image = resized_image.resize(settings.PHOTO_CONFIG['max_size'], Image.ANTIALIAS)
resized_image.save(self.image.path)
And the following config in settings.py:
PHOTO_CONFIG = {
'max_size': (900, 900),
}
Now, when I upload JPG of exactly 900x900 size (500 kb), the uploaded one is compressed to about 100kb. Both are 900x900 and 72 dpi resolution.
How and why does this happen?
Upvotes: 0
Views: 65
Reputation: 4175
There could be several reasons for that, but in a nutshell it is probably because the default save parameters are not the ones used to create the original image.
It could notably be:
See the complete list of options of the save method for JPEG file, and their default value, and you should find out which one is different in your case.
Upvotes: 1