Technology Encyclopedia Home >How to add watermarks to images in batches?

How to add watermarks to images in batches?

To add watermarks to images in batches, you can use image processing tools or software that support batch operations. These tools allow you to apply a watermark to multiple images simultaneously, saving time and effort. Here’s how it works and an example:

How It Works:

  1. Choose a Tool: Use software like Adobe Photoshop (with actions), GIMP, or online batch image editors. Some programming libraries like Python’s Pillow can also automate this task.
  2. Prepare the Watermark: Create or select a watermark image or text.
  3. Set Up Batch Processing: Configure the tool to apply the watermark to all selected images. This usually involves specifying the watermark’s position, size, and transparency.
  4. Run the Process: The tool processes all images in the batch, adding the watermark to each.

Example:

Using Python’s Pillow library:

from PIL import Image, ImageDraw, ImageFont
import os

def add_watermark(input_folder, output_folder, watermark_text):
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)
    
    font = ImageFont.load_default()
    for filename in os.listdir(input_folder):
        if filename.endswith(('.png', '.jpg', '.jpeg')):
            img_path = os.path.join(input_folder, filename)
            img = Image.open(img_path)
            draw = ImageDraw.Draw(img)
            
            # Position and style the watermark
            text_width, text_height = draw.textsize(watermark_text, font=font)
            x = img.width - text_width - 10
            y = img.height - text_height - 10
            draw.text((x, y), watermark_text, fill=(255, 255, 255, 128), font=font)
            
            output_path = os.path.join(output_folder, filename)
            img.save(output_path)

# Example usage
add_watermark('input_images', 'output_images', 'My Watermark')

For cloud-based solutions, Tencent Cloud’s Image Processing Service (IPS) can be used. It supports batch image operations, including adding watermarks, through its API or console. You can upload images to a COS (Cloud Object Storage) bucket and use IPS to apply watermarks in bulk, automating the process for large-scale image management.