简体   繁体   English

在PHP中使用imagick对具有旋转和不透明度的图像进行水印处理

[英]watermark an image with rotation and opacity using imagick in php

How can i apply a watermark onto an image with rotation and opacity using imagick in php 我如何在PHP中使用imagick将水印应用于具有旋转和不透明度的图像

this is my code 这是我的代码

<?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;
?>

Get your watermark image and the image you want to add it to . 获取您的水印图像和要将其添加到的图像。

Them merge them using PHP ImageCopy function 他们使用PHP ImageCopy函数合并它们

<?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);
?>

Should do the trick.. 应该做的把戏..

In your example you are only missing the rotate image. 在您的示例中,您仅缺少旋转图像。

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

Imagick.rotateImage imagick.rotateImage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM