From 29f0975ecda1f1eaaa0fda6efeac57310a5f1503 Mon Sep 17 00:00:00 2001 From: Remilia Da Costa Faro Date: Wed, 14 May 2025 15:48:38 +0200 Subject: [PATCH] Added exiftool and function to remove GPS data from EXIF --- Dockerfile | 2 +- images/utils.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8d43a06..583db65 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM alpine:3.21 -RUN apk add curl python3 +RUN apk add curl python3 exiftool RUN adduser -D kakigoori USER kakigoori diff --git a/images/utils.py b/images/utils.py index 804a4cc..aee658d 100644 --- a/images/utils.py +++ b/images/utils.py @@ -1,3 +1,5 @@ +import subprocess + import boto3 from botocore.config import Config from django.conf import settings @@ -15,3 +17,14 @@ def get_b2_resource(): bucket = b2.Bucket(settings.S3_BUCKET) return bucket + + +def remove_exif_gps_data(image_data: bytes) -> bytes: + result = subprocess.run( + ["exiftool", "-gps:all=", "-"], input=image_data, capture_output=True + ) + + if not result.check_returncode(): + return image_data + else: + raise Exception(result.stderr)