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.(PECL imagick 2, PECL imagick 3)
Imagick::getIteratorIndex β ΠΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ ΠΈΠ½Π΄Π΅ΠΊΡ ΡΠ΅ΠΊΡΡΠ΅Π³ΠΎ Π°ΠΊΡΠΈΠ²Π½ΠΎΠ³ΠΎ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ
ΠΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ ΠΈΠ½Π΄Π΅ΠΊΡ ΡΠ΅ΠΊΡΡΠ΅Π³ΠΎ Π°ΠΊΡΠΈΠ²Π½ΠΎΠ³ΠΎ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ Π² ΠΎΠ±ΡΠ΅ΠΊΡΠ΅ Imagick. ΠΠ΅ΡΠΎΠ΄ Π΄ΠΎΡΡΡΠΏΠ΅Π½, Π΅ΡΠ»ΠΈ ΠΌΠΎΠ΄ΡΠ»Ρ Imagick ΡΠΊΠΎΠΌΠΏΠΈΠ»ΠΈΡΠΎΠ²Π°Π»ΠΈ Ρ Π²Π΅ΡΡΠΈΠ΅ΠΉ ImageMagick 6.2.9 ΠΈΠ»ΠΈ ΡΡΠ°ΡΡΠ΅.
Π‘ΠΈΠ³Π½Π°ΡΡΡΠ° ΡΡΠ½ΠΊΡΠΈΠΈ Π½Π΅ ΡΠΎΠ΄Π΅ΡΠΆΠΈΡ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠΎΠ².
ΠΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ ΡΠ΅Π»ΠΎΠ΅ ΡΠΈΡΠ»ΠΎ, ΡΠΎΠ΄Π΅ΡΠΆΠ°ΡΠ΅Π΅ ΠΈΠ½Π΄Π΅ΠΊΡ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ Π² ΡΡΠ΅ΠΊΠ΅.
Π€ΡΠ½ΠΊΡΠΈΡ Π²ΡΠ±ΡΠ°ΡΡΠ²Π°Π΅Ρ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ ImagickException, Π΅ΡΠ»ΠΈ Π²ΠΎΠ·Π½ΠΈΠΊΠ»Π° ΠΎΡΠΈΠ±ΠΊΠ°.
ΠΡΠΈΠΌΠ΅Ρ #1 ΠΡΠΈΠΌΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ Imagick::getIteratorIndex():
Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ, ΡΡΡΠ°Π½ΠΎΠ²ΠΊΠ° ΠΈ ΠΏΠΎΠ»ΡΡΠ΅Π½ΠΈΠ΅ ΠΈΠ½Π΄Π΅ΠΊΡΠ° ΠΈΡΠ΅ΡΠ°ΡΠΎΡΠ°
<?php
$im = new Imagick();
$im->newImage(100, 100, new ImagickPixel("red"));
$im->newImage(100, 100, new ImagickPixel("green"));
$im->newImage(100, 100, new ImagickPixel("blue"));
$im->setIteratorIndex(1);
echo $im->getIteratorIndex();
?>
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.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 :
<?php
// Author: holdoffhunger@gmail.com
// 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
// ---------------------------------------------
$imagick_type->readImageFile($file_handle_for_viewing_image_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");
?>