Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Imagick::flattenImages method is deprecated and it's use should be avoided"

Tags:

php

image

imagick

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"

like image 849
Adil Avatar asked Jan 11 '17 08:01

Adil


1 Answers

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);
like image 89
josemmo Avatar answered Nov 01 '22 18:11

josemmo