Skip to content

Commit

Permalink
File: Apply EXIF orientation to image when stripping EXIF metadata
Browse files Browse the repository at this point in the history
TYPE: Bugfix
LINK: OGC-1993
  • Loading branch information
Daverball authored Dec 18, 2024
1 parent e12dd0b commit 5859fb2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/onegov/file/attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from onegov.file.utils import get_svg_size
from onegov.file.utils import IMAGE_MIME_TYPES
from onegov.file.utils import word_count
from PIL import Image, UnidentifiedImageError
from PIL import Image, ImageOps, UnidentifiedImageError
from tempfile import SpooledTemporaryFile
from onegov.pdf.utils import extract_pdf_info

Expand Down Expand Up @@ -74,6 +74,9 @@ def strip_exif_and_limit_and_store_image_size(
params: _ImageSaveOptionalParams = {}

if has_exif:
# bake EXIF orientation into the image
ImageOps.exif_transpose(image, in_place=True)

# replace EXIF section with an empty one
params['exif'] = Image.Exif()

Expand Down
3 changes: 2 additions & 1 deletion src/onegov/file/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from onegov.core.utils import module_path
from onegov.file.utils import IMAGE_MIME_TYPES, get_image_size
from pathlib import Path
from PIL import Image
from PIL import Image, ImageOps
from tempfile import TemporaryDirectory


Expand Down Expand Up @@ -93,6 +93,7 @@ def generate_thumbnail(
output = BytesIO()

thumbnail: Image.Image = Image.open(fp)
ImageOps.exif_transpose(thumbnail, in_place=True)
thumbnail.thumbnail(self.size, Image.Resampling.LANCZOS)
thumbnail = thumbnail.convert('RGBA')

Expand Down

0 comments on commit 5859fb2

Please sign in to comment.