Can PHP be used to automate the process of adding watermarks to multiple images at once?

Yes, PHP can be used to automate the process of adding watermarks to multiple images at once. One way to achieve this is by using the GD library in PHP to manipulate images. By creating a PHP script that loops through a directory of images, adds a watermark to each image, and saves the watermarked images, you can automate the process efficiently.

<?php
// Set the directory where the images are located
$directory = 'images/';

// Set the watermark image
$watermark = imagecreatefrompng('watermark.png');

// Loop through the directory
$images = glob($directory . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
foreach ($images as $image) {
    // Open the image
    $img = imagecreatefromstring(file_get_contents($image));
    
    // Get the dimensions of the image and watermark
    $img_width = imagesx($img);
    $img_height = imagesy($img);
    $watermark_width = imagesx($watermark);
    $watermark_height = imagesy($watermark);
    
    // Calculate the position for the watermark
    $pos_x = $img_width - $watermark_width - 10;
    $pos_y = $img_height - $watermark_height - 10;
    
    // Add the watermark to the image
    imagecopy($img, $watermark, $pos_x, $pos_y, 0, 0, $watermark_width, $watermark_height);
    
    // Save the watermarked image
    imagepng($img, $directory . 'watermarked_' . basename($image));
    
    // Free up memory
    imagedestroy($img);
}

// Free up memory
imagedestroy($watermark);
?>