PHP 获取图片的主色调
程序员文章站
2022-05-23 15:35:37
...
代码中用到了php的图片扩展,所以使用之前,需要先安装PHP的Imagick扩展,具体安装如下(window下):
http://blog.csdn.net/shaerdong/article/details/46639245
http://blog.csdn.net/shaerdong/article/details/46639245
$average = new Imagick("./fruit/143511081321676_593.jpg");
$average->quantizeImage( 10, Imagick::COLORSPACE_RGB, 0, false, false );
$average->uniqueImageColors();
functionGetImagesColor( Imagick $im ){$colorarr = array();
$it = $im->getPixelIterator();
$it->resetIterator();
while( $row = $it->getNextIteratorRow() ){
foreach ( $rowas$pixel ){
$colorarr[] = $pixel->getColor();
}
}
return$colorarr;
}
$colorarr = GetImagesColor($average);
foreach($colorarras$val){
$r += $val['r'];
$g += $val['g'];
$b += $val['b'];
echo"