📌  相关文章
📜  PHP | ImagickPixelIterator getIteratorRow()函数

📅  最后修改于: 2022-05-13 01:56:30.808000             🧑  作者: Mango

PHP | ImagickPixelIterator getIteratorRow()函数

ImagickPixelIterator::getIteratorRow()函数是PHP中的一个内置函数,用于获取当前像素迭代器行。此函数用于在遍历图像像素时检查我们当前位于哪一行。

句法:

int ImagickPixelIterator::getIteratorRow( void )

参数:此函数不接受任何参数。

返回值:此函数返回一个包含当前像素迭代器行的整数值。

异常:此函数在出错时抛出 ImagickException。

下面给出的程序说明了PHP中的ImagickPixelIterator::getIteratorRow()函数

方案一:

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

方案二:

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:

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

输出:

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