ImagickPixelIterator::newPixelIterator()函數是PHP中的內置函數,用於獲取新的像素迭代器來迭代imagick圖像的像素。
用法:
bool ImagickPixelIterator::newPixelIterator( Imagick $wand )
參數:該函數接受單個參數$wand,該參數保存圖像以迭代像素。
返回值:成功時此函數返回TRUE。
以下示例程序旨在說明PHP中的ImagickPixelIterator::newPixelIterator()函數:
程序1:
<?php
// Create a new imagick object
$imagick = new Imagick();
// Create a image on imagick object
$imagick->newImage(800, 250, 'black');
// Create a new ImagickPixelIterator instance
$imageIterator = new ImagickPixelIterator();
// Get the pixels from the image
$imageIterator->newPixelIterator($imagick);
$i = 0;
// Loop through pixel rows
foreach ($imageIterator as $row => $pixels) {
$i++;
}
echo 'Total rows are ' . $i;
?>
輸出:
Total rows are 250
程序2:
<?php
// Create a new imagick object
$imagick = new Imagick();
// Create a image on imagick object
$imagick->newImage(800, 250, 'black');
// Create a new ImagickPixelIterator instance
$imageIterator = new ImagickPixelIterator();
// Get the pixels from the image
$imageIterator->newPixelIterator($imagick);
$colors = ['red', 'green', 'blue', 'yellow'];
$i = 0;
// Loop through pixel rows
foreach ($imageIterator as $row => $pixels) {
foreach ($pixels as $column => $pixel) {
// Set the color of each pixel lines to colors
$pixel->setColor($colors[$i % 4]);
}
$i++;
// 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.newpixeliterator.php
相關用法
- PHP ImagickPixelIterator setIteratorFirstRow()用法及代碼示例
- PHP ImagickPixelIterator getIteratorRow()用法及代碼示例
- PHP ImagickPixelIterator syncIterator()用法及代碼示例
- PHP ImagickPixelIterator resetIterator()用法及代碼示例
- PHP ImagickPixelIterator resetIterator()用法及代碼示例
- PHP ImagickPixelIterator setIteratorLastRow()用法及代碼示例
- PHP ImagickPixelIterator newPixelRegionIterator()用法及代碼示例
- PHP ImagickPixelIterator getPreviousIteratorRow()用法及代碼示例
- PHP ImagickPixelIterator __construct()用法及代碼示例
- PHP ImagickPixelIterator setIteratorRow()用法及代碼示例
- PHP ImagickPixelIterator getCurrentIteratorRow()用法及代碼示例
- PHP ImagickPixelIterator getNextIteratorRow()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | ImagickPixelIterator newPixelIterator() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。