當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP ImagickPixelIterator getIteratorRow()用法及代碼示例


ImagickPixelIterator::getIteratorRow()函數是PHP中的內置函數,用於獲取當前像素迭代器行。此函數用於在遍曆圖像像素時檢查我們當前位於哪一行。

用法:

int ImagickPixelIterator::getIteratorRow( void )

參數:此函數不接受任何參數。


返回值:該函數返回一個包含當前像素迭代器行的整數值。

異常:該函數在錯誤時引發ImagickException。

下麵給出的程序說明了PHP中的ImagickPixelIterator::getIteratorRow()函數:

程序1:

<?php 
// Create a new imagick object 
$imagick = new Imagick( 
    'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Get the pixel iterator 
$pixelIterator = $imagick->getPixelIterator(); 
  
// Get the current iterator row 
echo "Current row is " . $pixelIterator->getIteratorRow(); 
?>

輸出:

Current row is 0 // which is the default row from where we start

程序2:

<?php 
// Create a new imagick object 
$imagick = new Imagick( 
    'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
  
// Get the pixel iterator 
$pixelIterator = $imagick->getPixelIterator(); 
  
// Set the pixel iterator to 30 
$pixelIterator->setIteratorRow(30); 
  
// Get the current iterator row 
echo "Current row is " . $pixelIterator->getIteratorRow(); 
?>

輸出:

Current row is 30

程序3:

<?php 
// Create a new imagick object 
$imagick = new Imagick(); 
  
// Create a image on imagick object with size of 10x10 pixels 
$imagick->newImage(10, 10, 'black'); 
  
// Get the pixel iterator 
$imageIterator = $imagick->getPixelIterator(); 
  
// Loop through pixel rows 
foreach ($imageIterator as $row => $pixels) { 
  
   // Get the current iterator row 
   echo "Current row is " . $imageIterator->getIteratorRow() . '<br>'; 
  
} 
?>

輸出:

Current row is 0
Current row is 1
Current row is 2
Current row is 3
Current row is 4
Current row is 5
Current row is 6
Current row is 7
Current row is 8
Current row is 9

參考: https://www.php.net/manual/en/imagickpixeliterator.getiteratorrow.php



相關用法


注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | ImagickPixelIterator getIteratorRow() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。