The 5th Annual China PHP Conference


(PECL imagick 2.0.0)

Imagick::getIteratorIndexLit l'index de l'image active courante


int Imagick::getIteratorIndex ( void )

Lit l'index de l'image active courante dans l'objet Imagick. Cette méthode n'est disponible que si Imagick a été compilé avec ImageMagick version 6.2.9 ou supérieur.

Valeurs de retour

Retourne un entier représentant l'index de l'image dans la file d'attente.

Erreurs / Exceptions

Lance une exception ImagickException si une erreur survient.


Exemple #1 Exemple avec Imagick::getIteratorIndex()

Crée des images, définit et récupère l'index de l'itérateur.

= new Imagick();
$im->newImage(100100, new ImagickPixel("red"));
$im->newImage(100100, new ImagickPixel("green"));
$im->newImage(100100, new ImagickPixel("blue"));


Voir aussi

add a note add a note

User Contributed Notes 2 notes

Michael O&#39;Connell
1 year ago
This will also retrieve which page number of a multipage document (i.e. PDF, PS) file the Imagick instance is currently on.  By default for a PDF it seems to be set to the last page.
holdoffhunger at gmail dot com
5 years ago
The getIteratorIndex function of the ImageMagick function works on any type of image, but it is built for measuring the number of frames in an animated .gif file.  For non-animated image files, like regular .bmp or .jpg files, this function will always return the number '0', meaning that there is only one frame.  Counting starts from zero with this function, so a .gif file with five different frames will return a value of '4' on this.  Highly repetitive, but psychedelic animated GIF's are often anywhere between 10 and 30 frames, but a .gif file that is nothing more than video footage converted to a datafile may have hundreds of frames.

According to Wikipedia (in the article for "Graphics Interchange Format"), an animated GIf image is a uses the GIF standard "which allows various images (frames) in the file to be painted with time delays."  This function won't get you the amount of time that delays between each frame, but it will give you the number of unique frames in a .gif file.  This will tell you how complicated or simple the animation may be.

Is the 'getIteratorIndex' function not working for you?  Try the 'getImageIndex' function, which produces the same exact result.

Some sample code :


// Author:
        // Imagick Type
        // ---------------------------------------------

$imagick_type = new Imagick();
// Open File
        // ---------------------------------------------
$file_to_grab = "image_workshop_directory/test.gif";
$file_handle_for_viewing_image_file = fopen($file_to_grab, 'a+');
// Grab File
        // ---------------------------------------------

// Get Image Type Value
        // ---------------------------------------------
$image_iterator_index = $imagick_type->getIteratorIndex();
// Print Image Type Value
        // ---------------------------------------------
print("Number of Unique Frames in the .GIF File: $image_iterator_index");

To Top