Monday, October 6, 2025
HomeLanguagesPHP | Imagick setImageIterations() Function

PHP | Imagick setImageIterations() Function

The Imagick::setImageIterations() function is an inbuilt function in PHP which is used to set the image iterations. The iteration here actually means for how many times the frames should repeat themselves.

Syntax:

bool Imagick::setImageIterations( int $iterations )

Parameters: This function accepts a single parameter $iterations which holds the number of iterations. Set to 0 to make it loop forever.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below programs illustrate the Imagick::setImageIterations() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagickAnimation = new Imagick(
  
foreach ($imagickAnimation as $frame) {
  
    // Add delay of 3 seconds
    $frame->setImageDelay(300);
}
  
// Set the interations
$imagickAnimation = $imagickAnimation->coalesceImages();
$imagickAnimation->setImageIterations(1);
  
// Display the image
header("Content-Type: image/gif");
echo $imagickAnimation->getImagesBlob();
?>


Output:

Program 2:




<?php
  
// Create a new imagick object
$imagickAnimation = new Imagick(
  
// Set the interations to 0 (infinite loop)
$imagickAnimation = $imagickAnimation->coalesceImages();
$imagickAnimation->setImageIterations(0);
  
// Display the image
header("Content-Type: image/gif");
echo $imagickAnimation->getImagesBlob();
?>


Output:

Reference: https://www.php.net/manual/en/imagick.setimageiterations.php

RELATED ARTICLES

Most Popular

Dominic
32338 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6707 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6825 POSTS0 COMMENTS
Ted Musemwa
7090 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6782 POSTS0 COMMENTS