簡體   English   中英

在PHP中使用imagick對具有旋轉和不透明度的圖像進行水印處理

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

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

應該做的把戲..

在您的示例中,您僅缺少旋轉圖像。

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

imagick.rotateImage

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM