Reputation: 107
Using PHP (GD or ImageMagick) I want to merge an animated gif with a jpg and retain the animation of the gif, the product being an animated gif.
In other words, I've got an animated gif that is 500px x 30px and needs to lay on top of a jpg thats 500px x 500px, the end result being a single animated gif.
So again, anyone know if it's possible to merge an animated gif with a jpg and retain the gifs animation?
Upvotes: 6
Views: 2387
Reputation: 1258
Look Imagick::animateImages method, gomadurai sample:
<?php
$multiTIFF = new Imagick();
$mytifspath = "./man"; // your image directory
$files = scandir($mytifspath);
//print_r($files);
/*foreach( $files as $f )
{*/
for($i=2;$i<6;$i++)
{
echo $files[$i];
echo "<br>";
$auxIMG = new Imagick();
$auxIMG->readImage($mytifspath."/".$files[$i]);
$multiTIFF->addImage($auxIMG);
}
//file multi.TIF
$multiTIFF->writeImages('multi423432.gif', true); // combine all image into one single image
//files multi-0.TIF, multi-1.TIF, ...
$multiTIFF->writeImages('multi.gif', false);
?>
If you use only one gif, you can save it splitted on a folder, then merge separated images with a simple GD manipulation (one of the comments here), and after use the code above to create the new Gif.
Upvotes: 1