PHP imagick gif to jpg - background

北战南征 提交于 2019-12-11 11:09:58

问题


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)


回答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(); 


来源:https://stackoverflow.com/questions/28154179/php-imagick-gif-to-jpg-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!