You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importpiexiffromPILimportImagedefremove_sensitive_data(input_image_path, output_image_path):
# Open the image using Pillow (PIL)image=Image.open(input_image_path)
# Get the Exif data from the imageexif_dict=piexif.load(image.info["exif"])
# Remove sensitive fields from the Exif datasensitive_tags= [
piexif.ExifIFD.Artist, # Artist/Author informationpiexif.ExifIFD.DateTimeOriginal, # Date and time when the photo was takenpiexif.GPSIFD.GPSLatitude, # GPS Latitudepiexif.GPSIFD.GPSLongitude, # GPS Longitudepiexif.ImageIFD.Make, # Camera makepiexif.ImageIFD.Model, # Camera model
]
forifdin ("0th", "Exif", "GPS", "1st"):
fortaginsensitive_tags:
iftaginexif_dict[ifd]:
exif_dict[ifd].pop(tag)
# Save the modified Exif data back to the imageexif_bytes=piexif.dump(exif_dict)
image.save(output_image_path, exif=exif_bytes)
# Example usageinput_image_path="input.jpg"output_image_path="output.jpg"remove_sensitive_data(input_image_path, output_image_path)
rotate the image based on the EXIF orientation metadata value, save the already rotated image to the server, and remove the tag completely or reset the EXIF orientation tag to "0".
A value of "0" in EXIF orientation tag signifies that the tag should be ignored according to the documentation.
Please also note to transform previous images that are already on the server, after choosing one of the two proposed solutions to keep the consistency.
from PIL import Image, ExifTags, ImageOps
from PIL.ExifTags import TAGS
# find exif orientation metadata of an image
def find_image_exif_orientation(original_image_file):
orientation = None
with Image.open(original_image_file) as pilImg:
img_exif = pilImg.getexif()
if img_exif is not None:
for key, val in img_exif.items():
if key in ExifTags.TAGS and key == 274:
orientation = val
#print('{}: {} key number:{}'.format(TAGS[key], val, key))
return orientation
Example
Also see: #52
The text was updated successfully, but these errors were encountered: