I am trying to merge two images - a GIF image with a smaller JPG image. The output should be GIF.
The issue is that GIF image colors remain correct, but the colors of the JPG image are altered.
The GIF image has only 256 colors (8-bit), but is there a way to make the merged image to be a true-color resource which later can be converted to a 8-bit GIF for output?
I updated the code. Here is the solution which works fine:
<?php
header('Content-Type: image/gif');
$gif_address = 'file.gif';
$jpg_address = 'file.jpg';
$image1 = imagecreatefromgif($gif_address);
$image2 = imagecreatefromjpeg($jpg_address);
$merged_image = imagecreatetruecolor(800, 800);
imagecopymerge($merged_image, $image1, 0, 0, 0, 0, 800, 800, 100);
imagecopymerge($merged_image, $image2, 0, 0, 0, 0, 500, 500, 100);
imagegif($merged_image);
imagedestroy($image1);
imagedestroy($image2);
imagedestroy($merged_image);
?>
From your explanation (some code would help), i would hazard a guess you are merging the jpeg onto the gif. Id say the easiest way is to use imageCreateTrueColor to create a new image the size you need then use imagecopy to copy the GIF into this new image. Merge the jpg onto this and then at a later date you can covert the true colour image to a gif.
If im missing something a bit of example code of what you are currently doing might help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With