PHP | ImagickPixelIterator getCurrentIteratorRow()函数
ImagickPixelIterator::getCurrentIteratorRow()函数是PHP中的一个内置函数,用于从像素迭代器获取当前行作为 ImagickPixel 对象的数组。
句法:
array ImagickPixelIterator::getCurrentIteratorRow( void )
参数:此函数不接受任何参数。
返回值:此函数返回一个数组值,其中包含本身可以迭代的 ImagickPixel 对象。
异常:此函数在出错时抛出 ImagickException。
下面给出的程序说明了PHP中的ImagickPixelIterator::getCurrentIteratorRow()函数:
程序 1(获取第一行的前五个像素):
newImage(5, 10, 'black');
// Get the pixel iterator
$pixelIterator = $imagick->getPixelIterator();
// Get the current iterator row
$row = $pixelIterator->getCurrentIteratorRow();
print("".print_r($row, true)."
");
?>
输出:
Array
(
[0] => ImagickPixel Object
(
)
[1] => ImagickPixel Object
(
)
[2] => ImagickPixel Object
(
)
[3] => ImagickPixel Object
(
)
[4] => ImagickPixel Object
(
)
)
程序2(获取第一行前五个像素的颜色):
getPixelIterator();
// Get the current iterator row
$row = $pixelIterator->getCurrentIteratorRow();
echo "First five colors of pixels are:
";
print("Pixel 1:" . "".print_r($row[0]->getColor(), true)."
");
print("Pixel 2:" . "".print_r($row[1]->getColor(), true)."
");
print("Pixel 3:" . "".print_r($row[2]->getColor(), true)."
");
print("Pixel 4:" . "".print_r($row[3]->getColor(), true)."
");
print("Pixel 5:" . "".print_r($row[4]->getColor(), true)."
");
?>
输出:
First five colors of pixels are:
Pixel 1:
Array
(
[r] => 255
[g] => 255
[b] => 255
[a] => 1
)
Pixel 2:
Array
(
[r] => 255
[g] => 255
[b] => 255
[a] => 1
)
Pixel 3:
Array
(
[r] => 255
[g] => 255
[b] => 255
[a] => 1
)
Pixel 4:
Array
(
[r] => 255
[g] => 255
[b] => 255
[a] => 1
)
Pixel 5:
Array
(
[r] => 255
[g] => 255
[b] => 255
[a] => 1
)
参考: https://www. PHP.net/manual/en/imagickpixeliterator.getcurrentiteratorrow。 PHP