文字

Imagick::getPixelIterator

(PECL imagick 2.0.0)

Imagick::getPixelIteratorReturns a MagickPixelIterator

说明

ImagickPixelIterator Imagick::getPixelIterator ( void )

Returns a MagickPixelIterator.

返回值

Returns an ImagickPixelIterator on success.

错误/异常

错误时抛出 ImagickException。

范例

Example #1 Imagick::getPixelIterator()

<?php
function  getPixelIterator ( $imagePath ) {
    
$imagick  = new \ Imagick ( realpath ( $imagePath ));
    
$imageIterator  $imagick -> getPixelIterator ();

    foreach (
$imageIterator  as  $row  =>  $pixels ) { 
        
foreach ( $pixels  as  $column  =>  $pixel ) { 
            
            
if ( $column  2 ) {
                
$pixel -> setColor ( "rgba(0, 0, 0, 0)" ); 
            
}
        }
        
$imageIterator -> syncIterator (); 
    
}

    
header ( "Content-Type: image/jpg" );
    echo 
$imagick ;
}

?>

用户评论:

[#1] Sebastian Herold [2008-06-30 01:06:20]

For me it was very helpful to read a article at Mikko's blog. He showed that the PixelIterator is not read-only, if you sync it regularly:

<?php
      

      
$im = new Imagick"strawberry.png" );

      

      
$it $im->getPixelIterator();
       
      

      
foreach( $it as $row => $pixels )
      {
          

          
if ( $row )
          {
              

              
foreach ( $pixels as $column => $pixel )
              {
                      

                      
if ( $column )
                      {
                              
$pixel->setColor"black" );
                      }
              }

          }
         
          

          
$it->syncIterator();
      }
       
      

      
header"Content-Type: image/png" );
      echo 
$im;
       
?>

上一篇: 下一篇: