I work on a photo site where I want the user to be able to upload portrait or landscape photographs. The maximum width should be 1250px, but the maximum height can be 1667px if it is in portrait mode. When I upload photos in portrait orientation, they are displayed 90 degrees to the left. Is there a way to use a pillow to make sure the photo stays in the correct orientation?
This is my code:
class Result(models.Model): result01 = models.FileField(upload_to=get_upload_file_name, null=True, blank=True) result01thumb = models.FileField(upload_to=get_upload_file_name, null=True, blank=True) def save(self): super(Result, self).save() if self.result01: size = 1667, 1250 image = Image.open(self.result01) image.thumbnail(size, Image.ANTIALIAS) fh = storage.open(self.result01.name, "w") format = 'png' image.save(fh, format) fh.close()
Itβs important that users can upload photos from their phones while theyβre mobile, so proper orientation is really important. Can I do anything here?
source share