Two examples for thumbnailing, one taken from geeksforgeeks:
# importing Image class from PIL package
from PIL import Image
# creating a object
image = Image.open(r"C:\Users\System-Pc\Desktop\python.png")
MAX_SIZE = (100, 100)
image.thumbnail(MAX_SIZE)
# creating thumbnail
image.save('pythonthumb.png')
image.show()
The second example relates to Python/Django.
If you do that on a django model.py, you modify the def save(self,*args, **kwargs)
method - like this:
class Profile(models.Model):
user=models.OneToOneField(User, on_delete=models.CASCADE)
image=models.ImageField(default='default.jpg', upload_to='img_profile')
def __str__(self):
return '{} Profile'.format(self.user.email)
# Resize the uploaded image
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
img=Image.open(self.image.path)
if img.height > 100 or img.width >100:
Max_size=(100,100)
img.thumbnail(Max_size)
img.save(self.image.path)
else:
del img
In the last example both images remain stored in the file system on your server.