How can PHP be used to watermark images with copyright information when they are uploaded to a website?

To watermark images with copyright information when they are uploaded to a website using PHP, you can use the GD library to manipulate images. You can overlay text or an image with copyright information onto the uploaded image before saving it to the server. This ensures that all images uploaded to the website will have the copyright information embedded in them.

// Function to watermark an image with copyright information
function watermarkImage($sourceImage, $watermarkText, $outputImage) {
    $image = imagecreatefromjpeg($sourceImage);
    $color = imagecolorallocate($image, 255, 255, 255);
    $font = 'arial.ttf';
    $fontSize = 20;
    $x = 10;
    $y = 10;
    
    imagettftext($image, $fontSize, 0, $x, $y, $color, $font, $watermarkText);
    
    imagejpeg($image, $outputImage);
    imagedestroy($image);
}

// Usage example
$sourceImage = 'uploaded_image.jpg';
$watermarkText = 'Copyright © Your Website';
$outputImage = 'watermarked_image.jpg';

watermarkImage($sourceImage, $watermarkText, $outputImage);