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);
Related Questions
- What best practices should be followed when retrieving multiple values from a database in PHP?
- How can the behavior of the Progress Class script be affected by different web browsers and their rendering capabilities?
- Is it recommended to develop a custom template system for smaller projects with a few developers, or is it better to use an existing one?