6

i cant use flatternImages() function becouse it's deprecated.

I must use

$im->setImageAlphaChannel(\Imagick::ALPHACHANNEL_REMOVE);
$im->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);

But ALPHACHANNEL_REMOVE constant is undefined.

How can i solve this issue?

P.S. I tried to use 11 instead \Imagick::ALPHACHANNEL_REMOVE and get error:

"Unable to set image alpha channel"

Adil
  • 152
  • 2
  • 8
  • Can you say what version of Imagick and ImageMagick you are using....it must be quite old for ALPHACHANNEL_REMOVE to not be there. – Danack Jan 11 '17 at 13:11

1 Answers1

9

According to this answer on php.net you must be using an ImageMagick version prior to 3.2.0b2.

At this point, you can either upgrade to the latest version of the library or use the value assigned to the constant Imagick::ALPHACHANNEL_REMOVE (which is 11):

$im->setImageBackgroundColor('white');
$im->setImageAlphaChannel(11); // Imagick::ALPHACHANNEL_REMOVE
$im->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
josemmo
  • 6,523
  • 3
  • 35
  • 49