PHP imagick gif to jpg - background


PHP imagick gif to jpg - background

我有这个gif:

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

(透明背景)

有了这个代码:

$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(); 

结果:

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

(金色背景)

但是想要这个:

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

(白色背景)

我已经找到了。是命令!

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

//错

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

//写!!!

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

其余代码...

$im->setImageFormat("jpg");    
$im->stripImage();    
$im->writeImage("example.jpg");    
$im->clear();    
$im->destroy();