11

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

Fotis
  • 1,322
  • 16
  • 30

1 Answers1

35

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);
Paul
  • 756
  • 1
  • 10
  • 22
  • Thnx for the reply, i'll try that out and let you know if it works :) – Fotis Sep 05 '10 at 00:20
  • Do you know any possible reason why EVALUATE_MULTIPLY does not work with some images while working with all the others? – effe Jun 26 '14 at 08:57
  • Great answer. Now that you've explained how setImageOpacity works, it makes much more sense. – Overcode Mar 29 '15 at 20:00
  • Marvelous! Saved me loads of time trying to find a solution for a supposedly simple problem. – Andris Sep 07 '15 at 11:53
  • This did not work for me. $img->evaluateImage(Imagick::EVALUATE_MULTIPLY, 0.5, Imagick::CHANNEL_ALPHA); also darkened the areas that were transparenty before. Any ideas? – Cymro Mar 31 '18 at 11:05