|
| 1 | +# Disclaimer: This script is for educational purposes only. |
| 2 | +# Do not use against any photos that you don't own or have authorization to test. |
| 3 | + |
| 4 | +#!/usr/bin/env python3 |
| 5 | + |
| 6 | +# This program is for .JPG and .TIFF format files. |
| 7 | +# Installation and usage instructions: |
| 8 | +# 1. Install Pillow (Pillow will not work if you have PIL installed): |
| 9 | +# python3 -m pip install --upgrade pip |
| 10 | +# python3 -m pip install --upgrade Pillow |
| 11 | +# 2. Add .jpg images downloaded from Flickr to subfolder ./images from where the script is stored. |
| 12 | +# Try the following Flickr account: https://www.flickr.com/photos/194419969@N07/? (Please don't use other Flickr accounts). |
| 13 | +# Note most social media sites strip exif data from uploaded photos. |
| 14 | + |
| 15 | + |
| 16 | +# Print Logo |
| 17 | +print(""" |
| 18 | +______ _ _ ______ _ _ |
| 19 | +| _ \ (_) | | | ___ \ | | | | |
| 20 | +| | | |__ ___ ___ __| | | |_/ / ___ _ __ ___ | |__ __ _| | |
| 21 | +| | | / _` \ \ / / |/ _` | | ___ \/ _ \| '_ ` _ \| '_ \ / _` | | |
| 22 | +| |/ / (_| |\ V /| | (_| | | |_/ / (_) | | | | | | |_) | (_| | | |
| 23 | +|___/ \__,_| \_/ |_|\__,_| \____/ \___/|_| |_| |_|_.__/ \__,_|_| |
| 24 | + |
| 25 | + |
| 26 | +
|
| 27 | + _______ _____________ _____ _____ _____ _ |
| 28 | +| ___\ \ / /_ _| ___| |_ _| _ || _ | | |
| 29 | +| |__ \ V / | | | |_ | | | | | || | | | | |
| 30 | +| __| / \ | | | _| | | | | | || | | | | |
| 31 | +| |___/ /^\ \_| |_| | | | \ \_/ /\ \_/ / |____ |
| 32 | +\____/\/ \/\___/\_| \_/ \___/ \___/\_____/ |
| 33 | + |
| 34 | + |
| 35 | +""") |
| 36 | + |
| 37 | + |
| 38 | +import os |
| 39 | +from PIL import Image |
| 40 | + |
| 41 | +# Add files to the folder ./images |
| 42 | +# We assign the cwd to a variable. We will refer to it to get the path to images. |
| 43 | +cwd = os.getcwd() |
| 44 | +# Change the current working directory to the one where you keep your images. |
| 45 | +os.chdir(os.path.join(cwd, "images")) |
| 46 | +# Get a list of all the files in the images directory. |
| 47 | +files = os.listdir() |
| 48 | + |
| 49 | +# Check if you have any files in the ./images folder. |
| 50 | +if len(files) == 0: |
| 51 | + print("You don't have have files in the ./images folder.") |
| 52 | + exit() |
| 53 | +# Loop through the files in the images directory. |
| 54 | +for file in files: |
| 55 | + # We add try except black to handle when there are wrong file formats in the ./images folder. |
| 56 | + try: |
| 57 | + img = Image.open(file) |
| 58 | + # We get the exif data from the which we'll overwrite |
| 59 | + img_data = list(img.getdata()) |
| 60 | + # We create a new Image object. We initialise it with the same mode and size as the original image. |
| 61 | + img_no_exif = Image.new(img.mode, img.size) |
| 62 | + # We copy the pixel data from img_data. |
| 63 | + img_no_exif.putdata(img_data) |
| 64 | + # We save the new image without exif data. The keyword argument exif would've been used with the exif data if you wanted to save any. We overwrite the original image. |
| 65 | + img_no_exif.save(file) |
| 66 | + except IOError: |
| 67 | + print("File format not supported!") |
0 commit comments