Skip to content

Commit 0996626

Browse files
committed
feat: initialize FastAPI application structure and implement thumbnail service
1 parent c375aa8 commit 0996626

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

app/main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4222,6 +4222,17 @@ async def upload_session_input_image(
42224222
status_code=400,
42234223
)
42244224

4225+
# Auto-rotate / transpose EXIF orientation if applicable
4226+
try:
4227+
with Image.open(io.BytesIO(data)) as img:
4228+
fmt = img.format or "JPEG"
4229+
transposed = ImageOps.exif_transpose(img)
4230+
buffer = io.BytesIO()
4231+
transposed.save(buffer, format=fmt)
4232+
data = buffer.getvalue()
4233+
except Exception as exc:
4234+
logger.warning(f"Failed to auto-rotate uploaded image: {exc}")
4235+
42254236
crud.upsert_chat_session_preferences(session, chat_session_id=token)
42264237

42274238
session_subdir = _session_input_subdir(token)

app/services/thumbnail_service.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ def create_thumbnail(self, base_dir: Path, image_relative_path: str | Path) -> P
2626
thumbnail_rel = self.thumbnail_relative_path(image_relative_path)
2727
thumbnail_abs = self.storage_service.resolve_managed_path(base_dir, thumbnail_rel)
2828

29+
from PIL import ImageOps
30+
2931
with Image.open(image_abs) as source:
30-
image = source.convert("RGB")
32+
transposed = ImageOps.exif_transpose(source)
33+
image = transposed.convert("RGB")
3134
image.thumbnail((self.max_px, self.max_px))
3235
buffer = BytesIO()
3336
image.save(buffer, format="WEBP", quality=85)

0 commit comments

Comments
 (0)