PHP | ImagickPixelIterator syncIterator() Function
Last Updated :
14 Jan, 2020
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: This function throws ImagickException on error.
Below given programs illustrate the ImagickPixelIterator::syncIterator() function in PHP:
Program 1:
<?php
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'black' );
$imageIterator = $imagick ->getPixelIterator();
foreach ( $imageIterator as $pixels ) {
foreach ( $pixels as $column => $pixel ) {
if ( $column % 11) {
$pixel ->setColor( 'yellow' );
}
}
$imageIterator ->syncIterator();
}
foreach ( $imageIterator as $pixels ) {
foreach ( $pixels as $column => $pixel ) {
if ( $column % 20) {
$pixel ->setColor( 'blue' );
}
}
$imageIterator ->syncIterator();
}
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Program 2:
<?php
$imagick = new Imagick(
$imageIterator = $imagick ->getPixelIterator();
foreach ( $imageIterator as $pixels ) {
foreach ( $pixels as $column => $pixel ) {
$HSL = $pixel ->getHSL();
$pixel ->setHSL( $HSL [ 'hue' ], 2, $HSL [ 'luminosity' ]);
}
$imageIterator ->syncIterator();
}
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/imagickpixeliterator.synciterator.php
Share your thoughts in the comments
Please Login to comment...