Skip to content
Related Articles
Open in App
Not now

Related Articles

PHP | Imagick setFirstIterator() function

Improve Article
Save Article
  • Last Updated : 17 Dec, 2019
Improve Article
Save Article

The Imagick::setFirstIterator() function is an inbuilt function in PHP which is used to set the Imagick iterator to the first image.

Syntax:

bool Imagick::setFirstIterator( void )

Parameters: This function doesn’t accept any parameter.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the Imagick::setFirstIterator() 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(
   
echo 'Index before setFirstIterator(); is '
    . $imagick->getIteratorIndex() 
    .'<br>';
   
// Set the Imagick iterator to the first image
$imagick->setFirstIterator();
   
echo 'Index after setFirstIterator(); is ' 
    . $imagick->getIteratorIndex() 
    .'<br>';
?>


Output:

Index before setFirstIterator(); is 1
Index after setFirstIterator(); is 0

Program 2:




<?php
// Create a new imagick object
$imagick = new Imagick();
   
// Array of images
$images = [
];
   
// Read the images
$imagick->readImages($images);
  
echo 'Index before setFirstIterator(); is ' 
    . $imagick->getIteratorIndex() 
    . '<br>';
  
// Set the Imagick iterator to the first image
$imagick->setFirstIterator();
  
echo 'Index after setFirstIterator(); is ' 
    . $imagick->getIteratorIndex() 
    . '<br>';
?>


Output:

Index before setFirstIterator(); is 2
Index after setFirstIterator(); is 0

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


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!