Professional Documents
Culture Documents
Kalyan Chatterjea
April 24, 2024
1 Introduction
This user manual guides you through using a Python program that adds water-
marks to images. A watermark is a semi-transparent image or text overlaid on
another image, often used to indicate ownership or branding.
2 Benefits
• Protection: Watermarks help protect images from unauthorized use by
adding a visible mark of ownership.
3 System Requirements
• Python 3 (download from https://www.python.org/downloads/)
• Python Imaging Library (PIL) or Pillow library (install using pip install
Pillow)
4 Usage
4.1 Prepare Watermark Image
Prepare a watermark image in JPEG or PNG format. This could be your logo
or signature.
1
4.2 Run the Program
1. Open a terminal or command prompt.
2. Navigate to the directory containing the program.
5 Function of K
The variable K in the program represents the padding around the watermark.
It determines the spacing between the watermark and the edges of the image.
By adjusting the value of K, you can control the size of the watermark and its
distance from the edges of the image.
6 Conclusion
The watermarking program offers a simple yet effective way to protect your
images and promote your brand. Follow the instructions in this manual to use
the program successfully.
For more information, visit: https://www.tutorialspoint.com/python_
pillow/python_pillow_creating_a_watermark.htm
2
7 Photo Example with Watermark
3
8 Program Code in 3 Listings
Args:
image_path (str): Path to the image file.
signature_path (str): Path to the watermark image
file.
position (int): Position of the watermark (1: top
left, 2: bottom left, 3: top right, 4: bottom
right).
Raises:
ValueError: If an invalid position is provided.
Exception: Any other error that occurs during
processing.
"""
try:
# Open the image and signature files
image = Image.open(image_path) # Open the image
file
signature = Image.open(signature_path).convert("
RGBA") # Open the signature file and convert to
RGBA mode
4
Listing 2: Python code with comments - contd.
def select_folder(default_folder="/home/kalyansg/Pictures")
:
"""
This function prompts the user to select a folder.
Args:
default_folder (str): Default folder path (default is "/
home/kalyansg/Pictures").
Returns:
str: Path to the selected folder.
"""
from tkinter import filedialog, Tk # Import necessary
modules
root = Tk() # Create Tkinter root window
root.withdraw() # Hide the main window
5
Listing 3: Python code with comments - contd.
def main():
"""
This function is the main entry point of the program. It
prompts the user for input and processes images in the
selected folder.
"""
folder_path = select_folder() # Select a folder for
processing
if not folder_path:
print("No folder selected. Exiting program.") # Print
message if no folder selected and exit
return