Search code examples
phpanimationgifanimated-gifgmagick

create GIF animation using Gmagick


I have some jpg files i want to create gif animated from them. i cant find useful method in gmagick for this problem. any one know about it?

I need simple example for it. ty


Solution

  • Gmagick example on how to create a GIF picture from two PNG files:

    $first = new Gmagick("example.0.png");
    $first->setImageformat("gif");
    $first->setImageDelay(100);
    $second = new Gmagick ("example.1.png");
    $first->nextImage();
    $first->addImage($second);
    $first->previousImage();
    $first->write('example.gif');
    

    Example taken from https://bugs.php.net/bug.php?id=59420

    Take care that Gmagick internally keeps track at which image you are, that is why nextImage­Docs is used before adding the second image and why previousImage­Docs is used before writing it to disk.

    Start with this two picture example and then change it to a version that adds pictures from an array and with three pictures. And then finally read the array from a directory from 0 to N pictures (e.g. with glob). Have fun!