PHP | ImagickPixelIterator resetIterator() Function
Last Updated :
14 Jan, 2020
The ImagickPixelIterator::resetIterator() function is an inbuilt function in PHP which is used to reset the pixel iterator.
Syntax:
bool ImagickPixelIterator::resetIterator( void )
Parameters:This function doesn’t accepts any parameter.
Return Value: This function returns TRUE on success.
Below programs illustrate the ImagickPixelIterator::resetIterator() function in PHP:
Program 1:
<?php
$imagick = new Imagick(
$pixelIterator = $imagick ->getPixelIterator();
$pixelIterator ->setIteratorRow(50);
echo "Before reset row is " . $pixelIterator ->getIteratorRow();
$pixelIterator ->resetIterator();
echo "<br>After reset row is " . $pixelIterator ->getIteratorRow();
?>
|
Output:
Before reset row is 50
After reset row is 0
Program 2:
<?php
$imagick = new Imagick(
$pixelIterator = $imagick ->getPixelIterator();
$pixelIterator ->setIteratorRow(40);
$row = $pixelIterator ->getCurrentIteratorRow();
echo "Colors of 61th and 62nd pixel from 40th row are:<br>" ;
print ( "Pixel 60:" . "<pre>" .print_r( $row [60]->getColor(), true). "</pre>" );
print ( "Pixel 61:" . "<pre>" .print_r( $row [61]->getColor(), true). "</pre>" );
$pixelIterator ->resetIterator();
$row = $pixelIterator ->getCurrentIteratorRow();
echo "First two colors of pixels from first row are:<br>" ;
print ( "Pixel 1:" . "<pre>" .print_r( $row [0]->getColor(), true). "</pre>" );
print ( "Pixel 2:" . "<pre>" .print_r( $row [1]->getColor(), true). "</pre>" );
?>
|
Output:
Colors of 61th and 62nd pixel from 40th row are:
Pixel 60:
Array
(
[r] => 110
[g] => 199
[b] => 131
[a] => 1
)
Pixel 61:
Array
(
[r] => 23
[g] => 165
[b] => 57
[a] => 1
)
First two colors of pixels from first row are:
Pixel 1:
Array
(
[r] => 255
[g] => 255
[b] => 255
[a] => 1
)
Pixel 2:
Array
(
[r] => 255
[g] => 255
[b] => 255
[a] => 1
)
Reference: https://www.php.net/manual/en/imagickpixeliterator.resetiterator.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...