Question

Hello people here is my code below...

        $_FILES=array();
        $GIF = new Imagick();
        $GIF->setFormat("gif");

        $_FILES['image0']="C:\wamp\www\latest\im\image0.gif";
        $_FILES['image1']="C:\wamp\www\latest\im\image1.gif";
        $_FILES['image2']="C:\wamp\www\latest\im\image2.gif";
        $_FILES['image3']="C:\wamp\www\latest\im\image3.gif";



        for ($i = 0; $i < sizeof($_FILES); ++$i) {


            $frame = new Imagick();
            $frame->readImage($_FILES["image$i"]);
            $frame->setImageDelay(100);
            $GIF->addImage($frame);
        }

        $GIF->writeImages("C:\wamp\www\latest\im\allimage.gif" , true);

above code works fine by creating an Animated gif, But the problem is it overlaps on the previous images,,,Iam trying to disappear the previous image when the next image comes... something like Timer ,... is there a way to fix this???

Was it helpful?

Solution

You should use setImageDispose method to clear the frame area:

$frame->readImage($_FILES["image$i"]);
$frame->setImageDispose(2);
$frame->setImageDelay(100);
  • Undefined: 0 -> No disposal specified (equivalent to 'none').
  • None: 1 -> Do not dispose, just overlay next frame image.
  • Background: 2 -> Clear the frame area with the background color.
  • Previous: 3 -> Clear to the image prior to this frames overlay.

And you could add a call to 'optimizeImageLayers' to reduce the size of your file:

$GIF->optimizeImageLayers();
$GIF->writeImages("C:\wamp\www\latest\im\allimage.gif" , true);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top