过多图纸站点都会基于用户上传的图样检索出图片的重要颜色值,您恐怕感兴趣的篇章

php获取图片SportageGB颜色值的例证

PHP将CMYK颜色值和奥迪Q五GB颜色相互转换的例子

数不胜数图片站点都会依照用户上传的图形检索出图片的重中之重颜色值,然后在经过颜色搜索相关的图片。

function hex2rgb($hex) {
$color = str_replace('#','',$hex);
$rgb = array('r' => hexdec(substr($color,0,2)),
'g' => hexdec(substr($color,2,2)),
'b' => hexdec(substr($color,4,2)));
return $rgb;
} // www.jbxue.com

function rgb2cmyk($var1,$g=0,$b=0) {
if (is_array($var1)) {
$r = $var1['r'];
$g = $var1['g'];
$b = $var1['b'];
} else {
$r=$var1;
}
$cyan = 255 - $r;
$magenta = 255 - $g;
$yellow = 255 - $b;
$black = min($cyan, $magenta, $yellow);
$cyan = @(($cyan - $black) / (255 - $black)) * 255;
$magenta = @(($magenta - $black) / (255 - $black)) * 255;
$yellow = @(($yellow - $black) / (255 - $black)) * 255;
return array('c' => $cyan / 255,
'm' => $magenta / 255,
'y' => $yellow / 255,
'k' => $black / 255);
}

$color=rgb2cmyk(hex2rgb('#FF0000'));

事先遵照网上的办法将图纸缩放(可能斯科学普及里克)然后遍历每一种像素点,然后总结处昂科雷GB次数最多的值,那做法功能太低而且取到的QashqaiGB值不够规范。之后才发现使用Imagick的quantizeImage方法能够很有益的取到图片中平均的HighlanderGB值.

你恐怕感兴趣的稿子:

$average = new Imagick("xiaocai.jpg");

$average->quantizeImage( 10, Imagick::COLORSPACE_RGB, 0, false, false );

$average->uniqueImageColors();

function GetImagesColor( Imagick $im ){

$colorarr = array();

$it = $im->getPixelIterator();

$it->resetIterator();

while( $row = $it->getNextIteratorRow() ){

foreach ( $row as $pixel ){
// www.jbxue.com
$colorarr[] = $pixel->getColor();

}

}

return $colorarr;

}

$colorarr = GetImagesColor($average);

foreach($colorarr as $val){

echo "<div style='background-color: rgb({$val['r']},{$val['g']},{$val['b']});width:50px;height:50px;float:left;'></div>";

} 

你大概感兴趣的稿子:

相关文章