Combine images in PHP - GIF and JPG

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); ?> 
+6
source share
1 answer

From your explanation (some code will help), I would venture to suggest that you combine jpeg on gif. Id says the easiest way is to use imageCreateTrueColor to create a new image the size you need and use imagecopy to copy the GIF to this new image. Drain the jpg onto this, and then at a later date you can hide the true color image to the gif.

If they are missing something, then an example code of what you are doing now can help.

+5
source

Source: https://habr.com/ru/post/899881/


All Articles