The Imagick::setLastIterator() function is an inbuilt function in PHP which is used to set the Imagick iterator to the last image.
Syntax:
bool Imagick::setLastIterator( void )
Parameters: This function doesn’t accepts any parameter.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below programs illustrate the Imagick::setLastIterator() function in PHP:
Program 1:
<?php // Create a new imagick object $imagick = new Imagick( // Add a new image to same object, this // will automatically move index to new // image which is added. $imagick ->addImage( new Imagick( // Move the cursor to first image $imagick ->setFirstIterator(); echo 'Index before setLastIterator() is ' . $imagick ->getIteratorIndex() . '<br>' ; // Set the Imagick iterator to the last image $imagick ->setLastIterator(); echo 'Index after setLastIterator() is ' . $imagick ->getIteratorIndex() . '<br>' ; ?> |
Output:
Index before setLastIterator() is 0 Index after setLastIterator() is 1
Program 2:
<?php // Create a new imagick object $imagick = new Imagick(); // Array of images $images = [ ]; // Read the images $imagick ->readImages( $images ); // Move iterator to first image $imagick ->setFirstIterator(); echo 'Index before setLastIterator() is ' . $imagick ->getIteratorIndex() . '<br>' ; // Set the Imagick iterator to the last image $imagick ->setLastIterator(); echo 'Index after setLastIterator() is ' . $imagick ->getIteratorIndex() . '<br>' ; ?> |
Output:
Index before setLastIterator() is 0 Index after setLastIterator() is 4
Reference: https://www.php.net/manual/en/imagick.setlastiterator.php