PHP想象gif到jpg - 背景

时间:2015-01-26 16:21:30

标签: php jpeg gif imagick alpha-transparency

我是这个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

(白色背景)

1 个答案:

答案 0 :(得分:1)

我找到了它。是订单!:

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