Search code examples
phpopacityimagick

Defining opacity when using Imagick::compositeImage in PHP


The problem is simple:

I want to composite an image on another with opacity.

$logo = createLogo($size); // returns Imagick object
$image->compositeImage($logo, Imagick::COMPOSITE_ATOP, x, y, width, height);

I would like to set the opacity of the $logo. It seems $logo->setImageOpacity is deprecated. What is the new way to achieve the same result?


Solution

  • You can try with:

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

    Where 0.3 is the percentage for opacity value, max 1.0, min 0.0.