©
Dokumen ini menggunakan Manual laman web PHP Cina Lepaskan
(PECL imagick 2.0.0)
Imagick::getPixelIterator — Returns a MagickPixelIterator
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 % 2 )
{
foreach ( $pixels as $column => $pixel )
{
if ( $column % 2 )
{
$pixel->setColor( "black" );
}
}
}
$it->syncIterator();
}
header( "Content-Type: image/png" );
echo $im;
?>