Imagick::getPixelIterator()函數是PHP中的內置函數,用於返回圖像MagickPixelIterator。
用法:
ImagickPixelIterator Imagick::getPixelIterator( void )
參數:該函數不接受任何參數。
返回值:此函數返回ImagickPixelIterator值。
錯誤/異常:此函數在錯誤時引發ImagickException。
以下示例程序旨在說明PHP中的Imagick::getPixelIterator()函數:
示例1:
<?php
// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
$imageIterator = $imagick->getPixelIterator();
// Change the color of every second pixel to green
foreach ($imageIterator as $row => $pixels) {
foreach ($pixels as $column => $pixel) {
if ($column % 2) {
$pixel->setColor("green");
}
}
$imageIterator->syncIterator();
}
// Display the output
header("Content-Type:image/png");
echo $imagick;
?>
輸出:
示例2:
<?php
// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
$imageIterator = $imagick->getPixelIterator();
// Change the color of every second pixel to green
foreach ($imageIterator as $row => $pixels) {
foreach ($pixels as $column => $pixel) {
if ($row % 2) {
$pixel->setColor("blue");
}
}
$imageIterator->syncIterator();
}
// Display the output
header("Content-Type:image/png");
echo $imagick;
?>
輸出:
參考: https://www.php.net/manual/en/imagick.getpixeliterator.php
相關用法
- PHP Imagick getImageCompose()用法及代碼示例
- PHP Imagick getImageChannelStatistics()用法及代碼示例
- PHP Imagick getImageClipMask()用法及代碼示例
- PHP Imagick getImageChannelMean()用法及代碼示例
- PHP Imagick getImageChannelExtrema()用法及代碼示例
- PHP Imagick setImageClipMask()用法及代碼示例
- PHP Imagick setImageBorderColor()用法及代碼示例
- PHP Imagick haldClutImage()用法及代碼示例
- PHP Imagick getImageBackgroundColor()用法及代碼示例
- PHP Imagick getImageChannelDistortion()用法及代碼示例
- PHP Imagick setImageBluePrimary()用法及代碼示例
- PHP Imagick getImageBorderColor()用法及代碼示例
- PHP Imagick setImageBackgroundColor()用法及代碼示例
- PHP Imagick setImageCompose()用法及代碼示例
- PHP Imagick setImageDelay()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | Imagick getPixelIterator() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。