How can ImageMagick be used to automatically add a watermark to images in PHP?
To automatically add a watermark to images using ImageMagick in PHP, you can use the "composite" function to overlay the watermark image onto the original image. You would need to have the ImageMagick PHP extension installed on your server.
// Path to original image
$originalImage = 'path/to/original/image.jpg';
// Path to watermark image
$watermarkImage = 'path/to/watermark.png';
// Create Imagick objects for original and watermark images
$original = new Imagick($originalImage);
$watermark = new Imagick($watermarkImage);
// Add watermark to original image
$original->compositeImage($watermark, Imagick::COMPOSITE_OVER, 0, 0);
// Save the modified image
$original->writeImage('path/to/save/final/image.jpg');
// Clear resources
$original->clear();
$watermark->clear();
Keywords
Related Questions
- What are the best practices for handling HTTP headers, specifically the "Location" header, in PHP scripts?
- What are the advantages and disadvantages of using wget to download a webpage with CSS included?
- How can the use of escaping characters like backslashes help in handling special characters within SQL queries in PHP?