I am trying to combine two images - a GIF image with a smaller JPG image. The output should be GIF .
The problem is that the GIF colors remain correct, but the colors of the JPG image are changed.
A GIF image has only 256 colors (8 bits), but is there a way to make the merged image a true color resource, which can later be converted to an 8-bit GIF for output?
The problem is resolved.
I updated the code. Here is a solution that works great:
<?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); ?>
source share