PHP | ImagickPixelIterator newPixelRegionIterator() Function Last Updated : 14 Jan, 2020 Comments Improve Suggest changes Like Article Like Report The ImagickPixelIterator::newPixelRegionIterator() function is an inbuilt function in PHP which is used to get a new pixel iterator from a specific region from the imagick wand. Syntax: bool ImagickPixelIterator::newPixelRegionIterator( Imagick $wand, int $x, int $y, int $columns, int $rows ) Parameters: This function accept five parameters as mentioned above and described below: $wand: It specifies the imagick wand. $x: It specifies the x-coordinate. $y: It specifies the y-coordinate. $columns: It specifies the number of columns. $rows: It specifies the numbers of rows. Return Value: This function returns TRUE on success. Exceptions: This function throws ImagickException on error. Below programs illustrate the ImagickPixelIterator::newPixelRegionIterator() function in PHP: Program 1: This program drawing a square on a blank image. php <?php // Create a new imagick object $imagick = new Imagick(); // Create a image on imagick object $imagick->newImage(800, 250, 'black'); // Create a new ImagickPixelIterator instance $imageIterator = new ImagickPixelIterator(); // Get the pixels from a image region $imageIterator->newPixelRegionIterator($imagick, 40, 30, 200, 200); // Loop through pixel rows foreach ($imageIterator as $row => $pixels) { foreach ($pixels as $column => $pixel) { // Set the color of each pixel $pixel->setColor('red'); } // Sync the iterator after each iteration $imageIterator->syncIterator(); } // Show the output $imagick->setImageFormat('png'); header("Content-Type: image/png"); echo $imagick->getImageBlob(); ?> Output: Program 2: This program drawing a rectangle on a png image. php <?php // Create a new imagick object $imagick = new Imagick( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Create a new ImagickPixelIterator instance $imageIterator = new ImagickPixelIterator(); // Get the pixels from a image region $imageIterator->newPixelRegionIterator($imagick, 40, 100, 1200, 20); // Loop through pixel rows foreach ($imageIterator as $row => $pixels) { foreach ($pixels as $column => $pixel) { // Set the color of each pixel $pixel->setColor('#62AC45'); } // Sync the iterator after each iteration $imageIterator->syncIterator(); } // Show the output $imagick->setImageFormat('png'); header("Content-Type: image/png"); echo $imagick->getImageBlob(); ?> Output: Reference: https://www.php.net/manual/en/imagickpixeliterator.newpixelregioniterator.php Comment More infoAdvertise with us Next Article PHP | ImagickPixelIterator newPixelRegionIterator() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Imagick Similar Reads PHP | ImagickPixelIterator resetIterator() Function 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 prog 2 min read PHP | ImagickPixelIterator syncIterator() Function The ImagickPixelIterator::syncIterator() function is an inbuilt function in PHP which is used to sync the pixel iterator. Syntax: bool ImagickPixelIterator::syncIterator( void ) Parameters:This function doesnât accepts any parameter. Return Value: This function returns TRUE on success. Exceptions: T 2 min read PHP | ImagickPixelIterator setIteratorRow() function 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 2 min read PHP | ImagickPixelIterator setIteratorLastRow() Function The ImagickPixelIterator::setIteratorLastRow() function is an inbuilt function in PHP which is used to set the pixel iterator to the last pixel row. Syntax: bool ImagickPixelIterator::setIteratorLastRow( void ) Parameters: This function doesnât accepts any parameters. Return Value: This function ret 1 min read PHP | ImagickPixelIterator setIteratorFirstRow() Function The ImagickPixelIterator::setIteratorFirstRow() function is an inbuilt function in PHP which is used to set the pixel iterator to the first pixel row. Syntax: bool ImagickPixelIterator::setIteratorFirstRow( void ) Parameters: This function doesnât accepts any parameter. Return Value: This function r 2 min read Like