I'm working on a photo website where I want the user to be able to upload a portrait or landscape oriented photo. The maximum width should be 1250px, but the maximum height could be 1667px if it's in portrait mode. When I upload photos in portrait orientation, they show up rotated 90 degrees to the left. Is there a way using 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 be able to upload photos from their phones while they're mobile, so the correct orientation is really important. Is there anything I can do here?
Aucun commentaire:
Enregistrer un commentaire