Here’s a simple Python script to apply a watermark to multiple images in a batch. This uses the Pillow library for image manipulation and os to handle file system operations. The watermark will be placed in the bottom right corner of each image.
Prerequisites:
You need to install the Pillow library if you haven’t already:
Python script:
How it works:
-
apply_watermark: This function applies a watermark text to a single image. It opens the image, creates a copy, and draws the watermark text in the bottom right corner with a slight transparency. -
batch_watermark: This function loops through all the images in the input directory, applies the watermark to each image, and saves the watermarked image in the output directory. -
The script handles
jpg,jpeg, andpngimages by checking their extensions.
Notes:
-
The watermark text is drawn with a white color and some transparency (alpha value = 128). You can modify the
fillparameter for different colors or transparency. -
You can change the font size or style by using
ImageFont.truetype()and providing a custom font file path.
Example Usage:
-
Place your images in a folder, for example,
images/. -
Define the input and output folder paths and the watermark text.
-
Run the script to apply watermarks to all images in the input folder and save the results in the output folder.