XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Add quality=75, exif=None to save thumbnail

6dbe827a
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +3 -16
Modified g4f/image/__init__.py +3 -16
@@ -11,16 +11,11 @@ from collections import defaultdict
11 11
12 12 try:
13 13 from PIL.Image import open as open_image, new as new_image
14 from PIL.Image import FLIP_LEFT_RIGHT, ROTATE_180, ROTATE_270, ROTATE_90
14 from PIL.Image import ROTATE_180, ROTATE_90
15 15 from PIL import Image, ExifTags
16 16 has_requirements = True
17 17 except ImportError:
18 18 has_requirements = False
19 try:
20 import piexif
21 has_piexif = True
22 except ImportError:
23 has_piexif = False
24 19
25 20 from ..typing import ImageType, Image
26 21 from ..errors import MissingRequirementsError
@@ -246,7 +241,7 @@ def process_image(image: Image, new_width: int = 800, new_height: int = 800, sav
246 241 if orientation:
247 242 debug.log(f"Image orientation: {orientation}")
248 243 if orientation == 6:
249 image = image.transpose(ROTATE_270)
244 image = image.transpose(ROTATE_90)
250 245 elif orientation == 3:
251 246 image = image.transpose(ROTATE_180)
252 247 image.thumbnail((new_width, new_height))
@@ -259,16 +254,8 @@ def process_image(image: Image, new_width: int = 800, new_height: int = 800, sav
259 254 # Convert to RGB for jpg format
260 255 elif image.mode != "RGB":
261 256 image = image.convert("RGB")
262 # Remove EXIF data
263 if has_piexif and save is not None:
264 try:
265 exif_dict = piexif.load(image.info["exif"])
266 except KeyError:
267 exif_dict = defaultdict(dict)
268 if exif_dict['Exif']:
269 exif_dict['Exif'] = {}
270 257 elif save is not None:
271 image.save(save)
258 image.save(save, quality=75, exif=None)
272 259 return image
273 260
274 261 def to_bytes(image: ImageType) -> bytes: