How can PHP be used to generate a watermark on an image?

To generate a watermark on an image using PHP, you can use the GD library functions to overlay a transparent watermark image onto the original image. First, you need to load both the original image and the watermark image using `imagecreatefromjpeg()` or `imagecreatefrompng()`. Then, you can use `imagecopy()` or `imagecopymerge()` to overlay the watermark onto the original image at the desired position. Finally, you can save the resulting image using `imagejpeg()` or `imagepng()`.

// Load the original image
$originalImage = imagecreatefromjpeg('original.jpg');

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

// Get the dimensions of the original image and watermark
$originalWidth = imagesx($originalImage);
$originalHeight = imagesy($originalImage);
$watermarkWidth = imagesx($watermark);
$watermarkHeight = imagesy($watermark);

// Set the position of the watermark (e.g., bottom right corner)
$positionX = $originalWidth - $watermarkWidth - 10;
$positionY = $originalHeight - $watermarkHeight - 10;

// Overlay the watermark onto the original image
imagecopy($originalImage, $watermark, $positionX, $positionY, 0, 0, $watermarkWidth, $watermarkHeight);

// Save the resulting image with the watermark
imagejpeg($originalImage, 'result.jpg');

// Free up memory
imagedestroy($originalImage);
imagedestroy($watermark);