fix: preserve exif data in optimized image (#27341)

This commit is contained in:
Raffael Meyer 2024-08-08 11:28:32 +02:00 committed by GitHub
parent cf869ed186
commit 71eb3704bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -52,6 +52,7 @@ def optimize_image(content, content_type, max_width=1024, max_height=768, optimi
try:
image = Image.open(io.BytesIO(content))
exif = image.getexif()
width, height = image.size
max_height = max(min(max_height, height * 0.8), 200)
max_width = max(min(max_width, width * 0.8), 200)
@ -66,6 +67,7 @@ def optimize_image(content, content_type, max_width=1024, max_height=768, optimi
optimize=optimize,
quality=quality,
save_all=True if image_format == "gif" else None,
exif=exif,
)
optimized_content = output.getvalue()
return optimized_content if len(optimized_content) < len(content) else content