fix: handle EXIF orientation to prevent image auto-rotation
This commit is contained in:
parent
64abb30172
commit
d1f4ea1fd2
@ -5,6 +5,9 @@ import base64
|
|||||||
import requests
|
import requests
|
||||||
from typing import Dict, Any, Union
|
from typing import Dict, Any, Union
|
||||||
import logging
|
import logging
|
||||||
|
import io
|
||||||
|
|
||||||
|
from PIL import Image, ImageOps
|
||||||
|
|
||||||
import jingrow
|
import jingrow
|
||||||
from jingrow.utils.auth import get_jingrow_cloud_api_headers, get_jingrow_cloud_api_url
|
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数据
|
# 解码base64数据
|
||||||
image_bytes = base64.b64decode(base64_content)
|
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"
|
api_url = f"{get_jingrow_cloud_api_url()}/rmbg/file"
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user