当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP ImagickPixelIterator syncIterator()用法及代码示例


ImagickPixelIterator::syncIterator()函数是PHP中的一个内置函数,用于同步像素迭代器。

用法:

bool ImagickPixelIterator::syncIterator( void )

参数:此函数不接受任何参数。


返回值:成功时此函数返回TRUE。

异常:该函数在错误时引发ImagickException。

下面给出的程序说明了PHP中的ImagickPixelIterator::syncIterator()函数:

程序1:

<?php 
// Create a new imagick object 
$imagick = new Imagick(); 
  
// Create a image on imagick object 
$imagick->newImage(800, 250, 'black'); 
  
$imageIterator = $imagick->getPixelIterator(); 
  
// Loop through rows pixel value 
foreach ($imageIterator as $pixels) { 
  
    // Loop through the pixels in the row value 
    foreach ($pixels as $column => $pixel) { 
  
        if ($column % 11) { 
            $pixel->setColor('yellow'); 
        } 
    } 
    // Sync the iterator after each iteration 
    $imageIterator->syncIterator(); 
} 
  
// Loop through pixel rows again for new color 
foreach ($imageIterator as $pixels) { 
    // Loop through the pixels in the row 
    foreach ($pixels as $column => $pixel) { 
        if ($column % 20) { 
            $pixel->setColor('blue'); 
        } 
    } 
  
    // Sync the iterator after each iteration 
    $imageIterator->syncIterator(); 
} 
  
// Show the output 
$imagick->setImageFormat('png'); 
header("Content-Type:image/png"); 
echo $imagick->getImageBlob(); 
?>

输出:

程序2:

<?php 
// Create a new imagick object 
$imagick = new Imagick( 
    'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
$imageIterator = $imagick->getPixelIterator(); 
  
// Loop through pixel rows 
foreach ($imageIterator as $pixels) { 
    // Loop through the pixels in the row 
    foreach ($pixels as $column => $pixel) { 
  
        // Get the current HSL 
        $HSL = $pixel->getHSL(); 
   
        // Set the HSL and change only saturation 
        $pixel->setHSL($HSL['hue'], 2, $HSL['luminosity']); 
    } 
    // Sync the iterator after each iteration 
    $imageIterator->syncIterator(); 
} 
  
// Show the output 
$imagick->setImageFormat('png'); 
header("Content-Type:image/png"); 
echo $imagick->getImageBlob(); 
?>

输出:

参考: https://www.php.net/manual/en/imagickpixeliterator.synciterator.php



相关用法


注:本文由纯净天空筛选整理自gurrrung大神的英文原创作品 PHP | ImagickPixelIterator syncIterator() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。