fix image orientation
This commit is contained in:
+4
-2
@@ -6,7 +6,7 @@ import subprocess
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from fastapi import HTTPException, UploadFile
|
||||
from PIL import Image, UnidentifiedImageError
|
||||
from PIL import Image, ImageOps, UnidentifiedImageError
|
||||
|
||||
try:
|
||||
from pillow_heif import register_heif_opener
|
||||
@@ -59,7 +59,9 @@ def process_upload(file: UploadFile | None) -> ProcessedImage | None:
|
||||
|
||||
|
||||
def _prepare_image(source_image: Image.Image) -> ProcessedImage:
|
||||
prepared = _strip_metadata_and_convert(source_image)
|
||||
# Normalize orientation from EXIF before resizing or stripping metadata.
|
||||
prepared = ImageOps.exif_transpose(source_image)
|
||||
prepared = _strip_metadata_and_convert(prepared)
|
||||
prepared.thumbnail((MAX_IMAGE_SIDE, MAX_IMAGE_SIDE))
|
||||
|
||||
output = BytesIO()
|
||||
|
||||
Reference in New Issue
Block a user