HomeImagickImagickDrawImagickPixelImagick Pixel IteratorImagick KernelDevelopmentTutorial Source codeReport an issue
Category
Example

Imagick::setImageDelay

← setImageCompressionQuality   setImageMask →
The delay can be set individually for each frame in an image.
Modify an animated Gif so that it's frames are played at a variable speed, varying between being shown for 50milliseconds down to 0ms, which will cause the frame to be skipped in most browsers.

Example

function setImageDelay()
{
    $imagick = new \Imagick(realpath("images/coolGif.gif"));

    $frameCount = 0;

    foreach ($imagick as $frame) {
        /** @var $frame \Imagick */
        $frame->setImageDelay((($frameCount % 11) * 5));
        $frameCount++;
    }

    $imagick2 = $imagick->deconstructImages();

    header("Content-Type: image/gif");
    echo $imagick2->getImagesBlob();
}