fix: preserve exif data in optimized image (#27341)
This commit is contained in:
parent
cf869ed186
commit
71eb3704bd
1 changed files with 2 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue