ImagickPixel::getColorCount()函數是PHP中的內置函數,用於獲取與像素顏色關聯的顏色計數。顏色計數是圖像中與此ImagickPixel顏色相同的像素數。 getColorCount()似乎僅適用於通過getImageHistogram()創建的ImagickPixel對象。
用法:
int ImagickPixel::getColorCount( void ):int
參數:此函數不接受任何參數。
返回值:此函數返回一個包含顏色計數的整數。
異常:該函數在錯誤時引發ImagickException。
下麵給出的程序說明了PHP中的ImagickPixel::getColorCount()函數:程序1:
<?php
// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
// Get the image histogram
$histogramElements = $imagick->getImageHistogram();
// Get the last index
$lastIndex = count($histogramElements) - 1;
// Get the element from array which is
// a ImagickPixel object
$lastColor = $histogramElements[$lastIndex];
// Get the Color count
echo $lastColor->getColorCount();
?>
輸出:
18
程序2:
<?php
// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
// Get the image histogram
$histogramElements = $imagick->getImageHistogram();
// Get the element from array which is
// a ImagickPixel object
$lastColor = $histogramElements[0];
// Get the Color count
echo $lastColor->getColorCount();
?>
輸出:
1
程序3:
<?php
// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
// Get the image histogram
$histogramElements = $imagick->getImageHistogram();
// Get the element from array which is
// a ImagickPixel object
$firstColor = $histogramElements[0];
// Set the Color count
$firstColor->setColorCount(20);
// Get the Color count
echo $firstColor->getColorCount();
?>
輸出:
20
程序3:
<?php
// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
// Get the image histogram
$histogramElements = $imagick->getImageHistogram();
// Get the whole color stats
echo "R G B Hue:Count<br>";
foreach ($histogramElements as $pixel) {
$colors = $pixel->getColor();
foreach ($colors as $color) {
print($color . " ");
}
print(":" . $pixel->getColorCount() . "<br>");
}
?>
輸出:
R G B Hue:Count 0 22 35 1:1 0 25 37 1:1 0 24 37 1:1 0 31 43 1:1 0 32 44 1:1 0 33 45 1:1 0 37 49 1:3 . . .
參考: https://www.php.net/manual/en/imagickpixel.getcolorcount.php
相關用法
- PHP GmagickPixel getcolorcount()用法及代碼示例
- PHP ImagickPixel setColorValue()用法及代碼示例
- PHP ImagickPixel getColor()用法及代碼示例
- PHP ImagickPixel setColorValueQuantum()用法及代碼示例
- PHP ImagickPixel setColor()用法及代碼示例
- PHP ImagickPixel isPixelSimilarQuantum()用法及代碼示例
- PHP ImagickPixel isSimilar()用法及代碼示例
- PHP ImagickPixel getIndex()用法及代碼示例
- PHP ImagickPixel __construct()用法及代碼示例
- PHP ImagickPixel setIndex()用法及代碼示例
- PHP ImagickPixel getColorAsString()用法及代碼示例
- PHP ImagickPixel getColorValue()用法及代碼示例
- PHP ImagickPixel getColorValueQuantum()用法及代碼示例
- PHP ImagickPixel getColorQuantum()用法及代碼示例
- PHP ImagickPixel setHSL()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | ImagickPixel getColorCount() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。