Currently making a basic Django project, following a well set out tutorial off youtube. All's going well and I usually try to debug issues myself and I wouldn't be asking if I was stuck.
Issue:
This code is meant to check the image size once it's reuploaded and then format to make it square but looking at the image linked, this isn't the case. Is my code wrong? is there another way to check and validate images?
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default="default.jpg", upload_to="profile_pics")
def __str__(self):
return f'{self.user.username} Profile'
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
img = Image.open(self.image.path)
if img.height > 300 or img.width > 300:
output_size = (300,300)
img.thumbnail(output_size)
img.save(self.image.path)
Reference Screenshot for Context
Update:
Hi Allan, tried your solution to this and now getting errors when uploading the image back.