From d1f4ea1fd2cdc138f16d9cecf545644726ea04d7 Mon Sep 17 00:00:00 2001 From: jingrow Date: Sun, 7 Dec 2025 06:40:59 +0800 Subject: [PATCH] fix: handle EXIF orientation to prevent image auto-rotation --- .../tools/remove_background/remove_background.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/jingrow/jingrow/tools/remove_background/remove_background.py b/apps/jingrow/jingrow/tools/remove_background/remove_background.py index 977e9a6..ed4921f 100644 --- a/apps/jingrow/jingrow/tools/remove_background/remove_background.py +++ b/apps/jingrow/jingrow/tools/remove_background/remove_background.py @@ -5,6 +5,9 @@ import base64 import requests from typing import Dict, Any, Union import logging +import io + +from PIL import Image, ImageOps import jingrow from jingrow.utils.auth import get_jingrow_cloud_api_headers, get_jingrow_cloud_api_url @@ -67,6 +70,14 @@ def remove_background_from_file(image_data: Union[str, list]) -> Dict[str, Any]: # 解码base64数据 image_bytes = base64.b64decode(base64_content) + # 处理EXIF orientation + image = Image.open(io.BytesIO(image_bytes)) + image = ImageOps.exif_transpose(image) + output = io.BytesIO() + save_format = image.format or content_type.split('/')[-1].upper() + image.save(output, format=save_format) + image_bytes = output.getvalue() + # 调用文件上传端点 api_url = f"{get_jingrow_cloud_api_url()}/rmbg/file"