This program provides photographers with a convenient tool to add professional-looking watermarks to their images, helping them protect their work, promote their brand, and preserve important metadata.
1. Program Description:
The program is a Python script designed to add a watermark to images based on their EXIF metadata. EXIF (Exchangeable Image File Format) data contains information about the image, such as camera settings, date and time of capture, location, etc. The program extracts relevant information from the EXIF data and overlays it as a watermark onto the image. This watermark typically includes details like the date and time of capture, location, photographer’s name, camera settings, and other customizable information.
2. Importance to Photographers:
This program is invaluable to photographers for several reasons:
- Protection: Adding a watermark to images helps protect them from unauthorized use or theft by clearly identifying the photographer and their ownership of the image.
- Branding: Watermarks can serve as a form of branding, helping photographers promote their work and establish their identity in the industry.
- Metadata Preservation: By embedding EXIF data into the image as a watermark, photographers ensure that important information about the image is preserved, even if the original metadata is stripped or modified.
- Professionalism: A well-designed watermark adds a professional touch to images, enhancing their presentation and credibility when shared online or in print.
3. Code Explanation:
Main Functions:
add_watermark(image_path)
: This function is the main entry point of the program. It opens the specified image file, extracts EXIF data, prompts the user for additional information (such as location and photographer), formats the shutter speed and date/time, creates a watermark text, calculates the font size, generates the watermark image, overlays it onto the original image, and finally saves the watermarked image to a new file.get_exif_data(image_path)
: This function extracts EXIF metadata from the given image file using the PIL library and returns it as a dictionary.get_user_info()
: This function prompts the user to input the location and photographer’s name and returns them.format_shutter_speed(shutter_speed)
: This function formats the shutter speed extracted from EXIF metadata into a human-readable format, such as “1/100s” or “0.01s”.
Supporting Functions:
create_watermark(text1, text2, width, height, font_size)
: This function creates a watermark image with two lines of text (text1 and text2) using the specified width, height, and font size.select_image()
: This function opens a file dialog to allow the user to select an image file interactively.
Additional Notes:
- The program uses the PIL (Python Imaging Library) to work with images and extract EXIF data.
- It utilizes Tkinter for the file dialog to select the image file.
- Custom font and font size are used for the watermark text.
- Watermark text includes information such as location, photographer, camera model, aperture, shutter speed, ISO, and focal length.
- Error handling is implemented to handle cases where certain EXIF metadata is not available or in unexpected formats.
from datetime import datetime
# Main function
def add_watermark(image_path):
# Open original image
image = Image.open(image_path)
width, height = image.size
# Extract EXIF data
exif_data = get_exif_data(image_path)
# Prompt user for additional information
location, photographer = get_user_info()
# Format shutter speed
shutter_speed = exif_data.get('ExposureTime', 'N/A')
formatted_shutter_speed = format_shutter_speed(shutter_speed)
# Format date and time
datetime_original = exif_data.get('DateTimeOriginal')
formatted_datetime = datetime.strptime(datetime_original, "%Y:%m:%d %H:%M:%S").strftime("%d %b %Y")
# Construct watermark text
text1 = f"{formatted_datetime}, {location}, {photographer}" # Include formatted date and time here
text2 = f"{exif_data.get('Model', 'N/A')}, f{exif_data.get('FNumber', 'N/A')}, {formatted_shutter_speed}, ISO-{exif_data.get('ISOSpeedRatings', 'N/A')}, {exif_data.get('FocalLength', 'N/A')}mm"
# Calculate font size based on the percentage of the image's actual height
font_size_percentage = 0.02 # You can adjust this percentage as needed
font_size = int(height * font_size_percentage)
# Create watermark
watermark = create_watermark(text1, text2, width, height, font_size)
# Paste watermark on original image
image.paste(watermark, (0, height - watermark.size[1]))
# Save the final image
output_path = os.path.splitext(image_path)[0] + "_watermarked.jpg"
image.save(output_path)
print(f"Watermark added. Saved as {output_path}")
User Manual for ExifWatermarker
- Install Python: Ensure Python is installed on your Windows system. If not, download and install Python from the official website (https://www.python.org/).
- Download ExifWatermarker: Download the “ExifWatermarker” Python script from the source.
- Open Command Prompt: Press the Windows key, type “cmd,” and press Enter to open the Command Prompt.
- Navigate to Script Directory: Use the “cd” command to navigate to the directory where the “ExifWatermarker” script is saved.
- Run the Script: Type “python ExifWatermarker.py” in the Command Prompt and press Enter to run the script.
- Select Image File: The program will prompt you to select the image file you want to watermark. Navigate to the location of the image and select it.
- Enter Information: Follow the on-screen instructions to enter the location, photographer, and optionally, the date.
- View Watermarked Image: Once you’ve provided the information, the program will automatically add a watermark to the selected image. You can now view the watermarked image in any image viewer or editor.
- Save Watermarked Image: The watermarked image will be saved in the same directory as the original image with “_watermarked” appended to the filename.
- Enjoy Your Watermarked Image: Your image is now ready with a personalized watermark containing the provided information. Share and enjoy your watermarked photos!