What are the advantages of using Imagick over GD for watermarking images in PHP?
When watermarking images in PHP, using Imagick over GD has several advantages. Imagick provides better image quality and supports a wider range of image formats. It also offers more advanced image manipulation features, making it easier to apply watermarks with transparency and other effects.
// Example code using Imagick for watermarking images
$image = new Imagick('image.jpg');
$watermark = new Imagick('watermark.png');
// Set the position for the watermark
$watermarkWidth = $watermark->getImageWidth();
$watermarkHeight = $watermark->getImageHeight();
$imageWidth = $image->getImageWidth();
$imageHeight = $image->getImageHeight();
$x = ($imageWidth - $watermarkWidth) / 2;
$y = ($imageHeight - $watermarkHeight) / 2;
// Apply the watermark to the image
$image->compositeImage($watermark, Imagick::COMPOSITE_OVER, $x, $y);
// Save or output the watermarked image
$image->writeImage('output.jpg');