Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With PHP, is it possible to merge an animated gif with a jpg and retain the gifs animation?

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?

like image 338
Ryan Dunlap Avatar asked Dec 02 '11 19:12

Ryan Dunlap


1 Answers

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.

like image 120
Paulo H. Avatar answered Sep 20 '22 14:09

Paulo H.