<?php
// Modify an animated gif so the first half of the gif is played at half the
// speed it currently is, and the second half to be played at double the speed
// it currently is
$imagick = new Imagick(realpath("Test.gif"));
$imagick = $imagick->coalesceImages();
$totalFrames = $imagick->getNumberImages();
$frameCount = 0;
foreach ($imagick as $frame) {
$imagick->setImageTicksPerSecond(50);
if ($frameCount < ($totalFrames / 2)) {
// Modify the frame to be displayed for twice as long as it currently is
$imagick->setImageTicksPerSecond(50);
} else {
// Modify the frame to be displayed for half as long as it currently is
$imagick->setImageTicksPerSecond(200);
}
$frameCount++;
}
$imagick = $imagick->deconstructImages();
$imagick->writeImages("/path/to/save/output.gif", true);
?>