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"