【问题标题】:watermark an image with rotation and opacity using imagick in php在 php 中使用 imagick 为带有旋转和不透明度的图像加水印
【发布时间】:2014-11-16 10:26:43
【问题描述】:

如何在 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;
?>

【问题讨论】:

  • 我要加水印

标签: php image-processing imagick


【解决方案1】:

获取您的水印图片和您想要添加到的图片。

他们使用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

【讨论】:

  • 我试过这个,但如果我有一个 png 图像,那么它就会失去透明
  • @user3262732 尝试在水印的构造函数中使用更新后的“透明”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-15
  • 1970-01-01
  • 2023-03-18
  • 1970-01-01
  • 2014-08-12
  • 1970-01-01
  • 2014-03-18
相关资源
最近更新 更多