📜  PHP | GmagickPixel getcolorcount()函数

📅  最后修改于: 2022-05-13 01:56:21.869000             🧑  作者: Mango

PHP | GmagickPixel getcolorcount()函数

GmagickPixel::getcolorcount()函数是PHP中的一个内置函数,用于获取与像素颜色相关的颜色计数。颜色计数是图像中与此 GmagickPixel 具有相同颜色的像素数。 getcolorcount()似乎只适用于通过getimagehistogram()函数创建的 GmagickPixel 对象。

句法:

int GmagickPixel::getcolorcount( void )

参数:此函数不接受任何参数。

返回值:此函数返回一个包含颜色计数的整数。

异常:此函数在错误时抛出 GmagickPixelException。

下面给出的程序说明了PHP中的GmagickPixel::getcolorcount()函数

使用图像:

方案一:

getImageHistogram(); 
    
// Get the last index 
$lastIndex = count($histogramElements) - 1; 
    
// Get the last element from array which is  
// a gmagickPixel object 
$lastColor = $histogramElements[$lastIndex]; 
    
// Get the Color count 
echo $lastColor->getcolorcount(); 
?>

输出:

100064

方案二:

getImageHistogram(); 
  
// Get the first element from array which is  
// a gmagickPixel object 
$firstColor = $histogramElements[0]; 
    
// Get the Color count 
echo $firstColor->getcolorcount(); 
?>

输出:

1

方案 3:

getImageHistogram(); 
  
// Get the whole color stats 
echo "R G B Hue :Count
";  foreach ($histogramElements as $pixel) {      $colors = $pixel->getcolor(true);      foreach ($colors as $color) {          print($color . " ");      }      print(":" . $pixel->getcolorcount() . "
");  }  ?>

输出:

R G B Hue :Count
0 22 35 :1
0 24 37 :1
0 25 37 :1
0 31 43 :1
0 32 44 :1
0 33 45 :1
0 36 48 :1
0 37 49 :3
.
.
.

参考: https://www. PHP.net/manual/en/gmagickpixel.getcolorcount。 PHP