Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
Strip EXIF from image before saving
Browse files Browse the repository at this point in the history
  • Loading branch information
BBaoVanC committed Nov 24, 2020
1 parent 86ec88d commit b11c7c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion imgupload.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pathlib import Path
import os
import datetime
from PIL import Image

import settings # app settings (such as allowed extensions)
import functions # custom functions
Expand Down Expand Up @@ -88,7 +89,14 @@ def upload():
if Path(os.path.join(settings.UPLOAD_FOLDER, fname)).is_file():
print("Requested filename already exists!")
return jsonify({'status': 'error', 'error': 'FILENAME_TAKEN'}), status.HTTP_409_CONFLICT
f.save(os.path.join(settings.UPLOAD_FOLDER, fname)) # save the image

f.save(f"/tmp/{fname}") # save the image temporarily (before removing EXIF)
image = Image.open(f"/tmp/{fname}")
data = list(image.getdata())
stripped = Image.new(image.mode, image.size)
stripped.putdata(data)
stripped.save(os.path.join(settings.UPLOAD_FOLDER, fname)) # save the image without EXIF

print(f"Saved to {fname}")
url = settings.ROOTURL + fname # construct the url to the image
if settings.SAVELOG != "/dev/null":
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Flask_API==2.0
Flask==1.1.2
Pillow==8.0.1

0 comments on commit b11c7c2

Please sign in to comment.