PHP 8.3.4 Released!

Imagick::setIteratorIndex

(PECL imagick 2, PECL imagick 3)

Imagick::setIteratorIndexイテレータの位置を設定する

説明

public Imagick::setIteratorIndex(int $index): bool

イテレータの位置を、画像リスト内の index で指定した位置に設定します。 このメソッドは、ImageMagick バージョン 6.2.9 以降で Imagick をコンパイルした場合に使用可能です。

パラメータ

index

イテレータを設定する場所。

戻り値

成功した場合に true を返します。

例1 Imagick::setIteratorIndex() の使用法

画像を作成し、インデックスを設定して取得します。

<?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();
?>

参考

add a note

User Contributed Notes 1 note

up
1
wilcobeekhuizen at gmail dot com
13 years ago
This function returns true on success but setting the iterator to an invalid index throws an exception instead of returning false:
Fatal error: Uncaught exception 'ImagickException' with message 'Unable to set iterator index'

This can happen when counting images inside a gif file, because the iterator count starts at zero and not one. If you count the number of images in a gif file be sure to use iterator 0 for the first image, like this:

<?php
$image
= new Imagick('simple.gif');
$image->setIteratorIndex(0);
?>
To Top