使用php中的imagick水印带有旋转和不透明度的图像

时间:2014-06-20 13:22:39

标签: php image-processing imagick

如何使用php中的imagick将水印应用于具有旋转和不透明度的图像

这是我的代码

<?php
$image = new Imagick();
$image->readImage(realpath('C:\xampp\htdocs\imagick\3.jpg'));

$watermark = new Imagick();
$watermark->readImage(realpath('C:\xampp\htdocs\imagick\1.png'));

$image->compositeImage($watermark, imagick::COMPOSITE_OVER, 0, 0);

header("Content-Type: image/" . $image->getImageFormat());
echo $image;
?>

1 个答案:

答案 0 :(得分:0)

获取水印图像和要添加的图像。

他们使用PHP ImageCopy function

合并它们
<?php
// Load the stamp and the photo to apply the watermark to
$watermark= imagecreatefrompng('stamp.png');
$im = imagecreatefromjpeg('photo.jpeg');

// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($watermark);
$sy = imagesy($watermark);

// Copy the stamp image onto our photo using the margin offsets and the photo 
// width to calculate positioning of the stamp. 
imagecopy($im, $watermark, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($watermark), imagesy($watermark));

// Output and free memory
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

应该做的伎俩..

在您的示例中,您只缺少旋转图像。

$imagick->rotateImage(new ImagickPixel('transparent'), -13.55); 

Imagick.rotateImage