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)

10
  • What's in your $save_as var? Also, why $im2? Commented Jan 26, 2015 at 16:23
  • $save_as = "example.jpg"; Commented Jan 26, 2015 at 16:26
  • Sorry, is $im not $im2 Commented Jan 26, 2015 at 16:29
  • Ok, just to clarify... You want to rename your rendered jpg as 2.jpg, is that? Commented Jan 26, 2015 at 16:29
  • No, I want to rendered gif as jpg. But with white backroung Commented Jan 26, 2015 at 16:31

1 Answer 1

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(); 
Sign up to request clarification or add additional context in comments.

5 Comments

I'm not sure I understand... there are constants like Imagick::ALPHACHANNEL_SET.
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

Your Answer

By clicking “Post Your Answer”, you agree to our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant