Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Imagick setImageOpacity destroys transparency and does nothing

Here's the thing.

I hava a simple snippet in PHP like this regarding a transparent image:

$im = new Imagick('some-transparent-image.png');
$im->setImageOpacity(0.3);
$im->writeImage('output.png');

The file output should be a transparent image with lower opacity, right?

Well, the output is an image with black color where it was supposed to be transparent and the image opacity is exactly the same.

Does it have to do with configuration or am i missing something?

Thank you in advance

like image 834
Fotis Avatar asked Aug 21 '10 20:08

Fotis


1 Answers

Unfortunately setImageOpacity affects the whole image, so to leave the transparent areas transparent replace the following:

$im->setImageOpacity(0.3); 

with :

$im->evaluateImage(Imagick::EVALUATE_MULTIPLY, 0.3, Imagick::CHANNEL_ALPHA);
like image 119
Paul Avatar answered Nov 05 '22 11:11

Paul