How can PHP be used to add a watermark or copyright text to images in a gallery?
To add a watermark or copyright text to images in a gallery using PHP, you can use the GD library to manipulate images. You would need to load the image, add the watermark or copyright text, and then save the modified image. This can be achieved by overlaying the text on the image using the `imagestring()` or `imagettftext()` function provided by the GD library.
<?php
// Load the image
$image = imagecreatefromjpeg('image.jpg');
// Set the copyright text
$text = "Copyright © Your Company";
// Set the font size and color
$font_size = 20;
$font_color = imagecolorallocate($image, 255, 255, 255);
// Add the text to the image
imagettftext($image, $font_size, 0, 10, 30, $font_color, 'arial.ttf', $text);
// Save the modified image
imagejpeg($image, 'watermarked_image.jpg');
// Free up memory
imagedestroy($image);
?>
Keywords
Related Questions
- In PHP, what are the potential pitfalls of directly inserting user input into SQL queries without proper sanitization or validation?
- Are there any specific considerations or configurations in PHP that could affect the ability to create cookies, especially when compared to other frameworks like Drupal?
- How can prepared statements be used in PHP to prevent SQL injection vulnerabilities when interacting with databases?