Search code examples
phpimagickanimated-gif

PHP Imagick - Animated GIF, frames per second


Into this code

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

for ($i = 0; $i < count($file_name); ++$i) {
     $frame = new Imagick();
     $frame->readImage($file_tmp[$i]);
     $frame->setImageDelay(10);
     $GIF->addImage($frame);
}

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

I've this part to set what I want

 $frame->setImageDelay(10);

Instead of 10, What is the correct equivalent for 24 frames per second?

[1 second / fps] >>> (1000/24) = 42 ?

Thanks!


Solution

  • From the php documents:

    The amount of time expressed in 'ticks' that the image should be displayed for. For animated GIFs there are 100 ticks per second, so a value of 20 would be 20/100 of a second aka 1/5th of a second.

    So, 24 fps, where a second is a value of 100, would be 100/24 or 4.1. The value must be an integer, so rounding down would be 4. It would be more natural to do 20 frames per second which would be a delay value of 5, or 25 frames per second which would give a delay value of 4.