简体   繁体   English

使用 imagick 更改图像的不透明度

[英]change opacity of image using imagick

I want to change opacity of multiple images when i used setImageOpacity it work fine for all images but not with png images and when i used evaluateImage it is work fine for transparent images but not for other images.当我使用setImageOpacity时,我想更改多个图像的不透明度,它适用于所有图像,但不适用于 png 图像,当我使用evaluateImage 时,它适用于透明图像,但不适用于其他图像。 how can i used same method for all types of images if image is transparent or not this is the code如果图像是否透明,我如何对所有类型的图像使用相同的方法这是代码

<?php
// Open the original image
$image = new Imagick();
$image->readImage(3.jpg);

// Open the watermark
$watermark = new Imagick();
$watermark->readImage(2.png);

    $watermark->setImageOpacity(0.444);
    //$watermark->evaluateImage(Imagick::EVALUATE_MULTIPLY, 0.0, Imagick::CHANNEL_ALPHA);


$watermark->rotateImage(new ImagickPixel('transparent'), 90); 
// Overlay the watermark on the original image
$image->compositeImage($watermark, imagick::COMPOSITE_OVER, 20, 20);

// send the result to the browser
header("Content-Type: image/" . $image->getImageFormat());
echo $image;  

use if condition using getImageAlphaChannel() function使用 if 条件使用getImageAlphaChannel()函数

to detect if the image have any transparent检测图像是否有任何透明

note :笔记 :

This method is available if Imagick has been compiled against ImageMagick version 6.4.0 or newer.如果已针对 ImageMagick 6.4.0 或更新版本编译了 Imagick,则此方法可用。

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

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