1

I've this gif:

https://dl.dropboxusercontent.com/u/76885657/stackoverflow/2.gif

(transparent background)

And with this code:

$im = new Imagick();    
$im->readimage("example.gif");     
$im->setImageAlphaChannel(11);    
$im->setImageBackgroundColor('white');    
$im->setImageFormat("jpg");    
$im->stripImage();    
$im->writeImage("example.jpg");    
$im->clear();    
$im->destroy(); 

Results:

https*://dl.dropboxusercontent.com/u/76885657/stackoverflow/3.jpg(without *)

(gold background)

But want this:

https://dl.dropboxusercontent.com/u/76885657/stackoverflow/2.jpg

(white background)

lucasgabmoreno
  • 1,001
  • 1
  • 10
  • 18

1 Answers1

1

I've found it. Was the order!:

$im = new Imagick();    
$im->readimage("example.gif"); 

// Wrong

$im->setImageBackgroundColor('white');  
$im->setImageAlphaChannel(11);  

// Write!!!

$im->setImageAlphaChannel(11);    
$im->setImageBackgroundColor('white');   

// Rest of code...

$im->setImageFormat("jpg");    
$im->stripImage();    
$im->writeImage("example.jpg");    
$im->clear();    
$im->destroy(); 
lucasgabmoreno
  • 1,001
  • 1
  • 10
  • 18
  • Could you explain why you used `11` instead of [Imagick constants](http://php.net/manual/en/imagick.constants.php#imagick.constants.alphachannel)? And especially, what does 11 mean? – aross Mar 26 '15 at 09:02
  • I used 11 instead of constants because is a channel, not a color. 11 is the number of channel to change. – lucasgabmoreno Mar 26 '15 at 11:27
  • I'm not sure I understand... there are constants like `Imagick::ALPHACHANNEL_SET`. – aross Mar 26 '15 at 12:34
  • 1
    Actually I believe 11 is the value of `Imagick::ALPHACHANNEL_REMOVE`, see: http://php.net/manual/en/imagick.flattenimages.php#116956 – aross Mar 26 '15 at 17:29
  • You are right, maybe 11 is the number of the constant used in the imagick class to reduce the class code. I don't really know – lucasgabmoreno Mar 26 '15 at 17:56