Question

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

Was it helpful?

Solution

setImageOpacity unfortunately affects the whole image, so to leave the transparent areas transparent replace $im->setImageOpacity(0.3); with :

$im->evaluateImage(Imagick::EVALUATE_MULTIPLY, 0.3, Imagick::CHANNEL_ALPHA);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top