Reputation: 9657
I have two gif images, one with a gray gradient background, and one image with a logo. So for example, in the images below, the green box is the logo.
My problem is that when I merge the two gif files using the PHP GD library, the green some how becomes orange/brown and won't return the original colour. Please can someone point out what I'm doing wrong?
$base_image = 'img_in.gif';
$logo_image = 'logo.gif';
// Create images from files
$source = imagecreatefromgif($base_image);
$logo = imagecreatefromgif($logo_image);
//---------------------Logo-----------------------------------\\
imagecolortransparent($logo, imagecolorallocate($logo, 0, 0, 0));
imagecopymerge($source, $logo, 152, 33, 0, 0, 153, 26, 100);
// -------------------------------Output--------------------------\\
imagegif($source,$image_out);
imagedestroy($source);
The green one is how it should look
The orange one is how it ends up looking
The above is how it should look The above is how it ends up looking
Upvotes: 2
Views: 222
Reputation: 9657
Thanks for the replies guys. I realised that I was saving the gif with only 63 colours and not 256! Doh! Thanks anyway
Upvotes: 0
Reputation: 11999
Since GIFs are pallet-base, each GIF can use 256 colors only - those allocated in its palette. If you copy one GIF into another one, the library needs to somehow homogenize palettes.
I'd propose to convert those GIFs to PNG (or some format with more colors), do the processing and finally convert back to GIF.
In general, results should look better.
Upvotes: 2