查詢

Gmagick::current()函式—用法及示例

「 獲取當前影象的迭代器位置 」


函式名:Gmagick::current()

適用版本:Gmagick擴充套件4.0.0及以上版本

用法:Gmagick::current() 函式用於獲取當前影象的迭代器位置。

示例:

// 建立一個新的Gmagick物件
$gmagick = new Gmagick('image.jpg');

// 設定迭代器到第一幀
$gmagick->setiteratorindex(0);

// 獲取當前迭代器位置
$current = $gmagick->current();
echo "當前迭代器位置:" . $current . PHP_EOL;

// 輸出當前幀的資訊
$frame = $gmagick->current();
var_dump($frame);

// 移動迭代器到下一幀
$gmagick->next();

// 獲取當前迭代器位置
$current = $gmagick->current();
echo "當前迭代器位置:" . $current . PHP_EOL;

// 輸出當前幀的資訊
$frame = $gmagick->current();
var_dump($frame);

輸出:

當前迭代器位置:0
object(GmagickPixelIterator)#2 (0) {
}
當前迭代器位置:1
object(GmagickPixelIterator)#3 (0) {
}

說明:Gmagick::current() 函式返回一個GmagickPixelIterator物件,該物件用於訪問當前幀的畫素資料。在示例中,我們首先建立一個Gmagick物件,然後使用setiteratorindex()方法將迭代器位置設定為第一幀。接著,我們使用current()方法獲取當前迭代器位置,並輸出其值。然後,我們再次使用current()方法獲取當前幀的資訊,並使用var_dump()函式輸出。接著,我們呼叫next()方法將迭代器位置移動到下一幀,並重復之前的步驟。最後,我們再次呼叫current()方法獲取當前迭代器位置和當前幀的資訊,並輸出。

補充糾錯
熱門PHP函式
分享連結