First, itβs best to set the correct language. Django and Python exist only on the server side. Therefore, everything that they manipulate, save or otherwise use must first be sent to the server. If Django or Python must manage the photo, the user MUST first upload the photo to the server. After uploading a photo, Django may make changes before saving the file.
If your problem is with download bandwidth and you do not want large files to load, you will have to resize and reformat the photo on the client side. If this is a web application, this can be done using Javascript, but it cannot be done using Python, because Python does not work on the client side for an application like yours.
If your concern is not bandwidth, you can ask the user to βdownloadβ the file, but then Django resizes it and formats it before saving.
You are correct that you want to override the save function for the photo object. I would recommend using a library to handle resizing and reformatting, such as sorl .
from sorl.thumbnail import ImageField, get_thumbnail class MyPhoto(models.Model): image = ImageField() def save(self, *args, **kwargs): if self.image: self.image = get_thumbnail(self.image, '500x600', quality=99, format='JPEG') super(MyPhoto, self).save(*args, **kwargs)
Sorl is just a library that I'm sure and familiar with, but it does require some tweaking and tweaking. You can check Pillow or something instead, and just replace the line that overlaps self.image .
I also found a similar question here .
Edit: saw the update of your comment answer above. Also note that if your web server processes Django and your files are stored in the database on some CDN, this method will work. The image will be resized on the web server before uploading it to the CDN (assuming that your configuration meets my expectations).
Hope this helps!