Thursday, September 4, 2025
HomeLanguagesPHP | Imagick setLastIterator() Function

PHP | Imagick setLastIterator() Function

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

RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS