PHP | ImagickPixelIterator setIteratorRow() function
Last Updated :
02 Jan, 2020
The ImagickPixelIterator::setIteratorRow() function is an inbuilt function in PHP which is used to set the pixel iterator row. This function is used to move to any row in the current image pixels.
Syntax:
bool ImagickPixelIterator::setIteratorRow( int $row )
Parameters:This function accepts a single parameter $row which holds the row number.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the ImagickPixelIterator::setIteratorRow() function in PHP:
Program 1:
<?php
$imagick = new Imagick(
$pixelIterator = $imagick ->getPixelIterator();
$pixelIterator ->setIteratorRow(50);
echo "Current row is " . $pixelIterator ->getIteratorRow();
?>
|
Output:
Current row is 50
Program 2:
<?php
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'black' );
$imageIterator = $imagick ->getPixelIterator();
$x = 0;
while ( $x < 250) {
$imageIterator ->setIteratorRow( $x );
$pixels = $imageIterator ->getCurrentIteratorRow();
foreach ( $pixels as $pixel ) {
if ( $x % 2) {
$pixel ->setColor( 'white' );
} else {
$pixel ->setColor( 'red' );
}
}
$imageIterator ->syncIterator();
$x = $x + 5;
}
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/imagickpixeliterator.setiteratorrow.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...