25
A
回答
20
這是一個scr ipt會給你的清單:
function detectColors($image, $num, $level = 5) {
$level = (int)$level;
$palette = array();
$size = getimagesize($image);
if(!$size) {
return FALSE;
}
switch($size['mime']) {
case 'image/jpeg':
$img = imagecreatefromjpeg($image);
break;
case 'image/png':
$img = imagecreatefrompng($image);
break;
case 'image/gif':
$img = imagecreatefromgif($image);
break;
default:
return FALSE;
}
if(!$img) {
return FALSE;
}
for($i = 0; $i < $size[0]; $i += $level) {
for($j = 0; $j < $size[1]; $j += $level) {
$thisColor = imagecolorat($img, $i, $j);
$rgb = imagecolorsforindex($img, $thisColor);
$color = sprintf('%02X%02X%02X', (round(round(($rgb['red']/0x33)) * 0x33)), round(round(($rgb['green']/0x33)) * 0x33), round(round(($rgb['blue']/0x33)) * 0x33));
$palette[$color] = isset($palette[$color]) ? ++$palette[$color] : 1;
}
}
arsort($palette);
return array_slice(array_keys($palette), 0, $num);
}
$img = 'icon.png';
$palette = detectColors($img, 6, 1);
echo '<img src="' . $img . '" />';
echo '<table>';
foreach($palette as $color) {
echo '<tr><td style="background:#' . $color . '; width:36px;"></td><td>#' . $color . '</td></tr>';
}
echo '</table>';
0
如果你可以調用一個外部工具,Imagemagick可以爲你生成一個直方圖。這可能比PHP實現要快得多。
基本上,這個命令給你的顏色列表,通過最具統治力的第一排序:
convert 'http://i.stack.imgur.com/J2txV.png' -format %c histogram:info:-|sort -r
您可能希望將圖像第一映射到一個固定的調色板(「圓關」的顏色)。這是我使用:
convert 'http://i.stack.imgur.com/J2txV.png' -modulate 100,200,100 -remap 'http://i.stack.imgur.com/GvTqB.png' -format %c histogram:info:-|sort -r
相關問題
- 1. 使用Python的圖像顏色檢測
- 2. 使用PHP檢測圖像中的主要顏色
- 3. 檢測圖像中的顏色斑點
- 4. 圖像中物體的顏色檢測
- 5. 檢測圖像的背景顏色
- 6. 圖像上的檢測顏色
- 7. 使用python檢測圖像中最常用的顏色
- 8. 使用PHP獲取圖像的顏色
- 9. PHP顏色強度檢測
- 10. 如何使用AS3和Adobe Air檢測圖像的顏色?
- 11. 使用OpenCV和Python檢測HSV圖像顏色的問題
- 12. PHP如何檢測圖像是否包含顏色?
- 13. 使用顏色斑點檢測器拍攝圖像Opencv
- 14. PHP背景圖像顏色
- 15. 檢測肖像圖像中的頭髮顏色
- 16. 用於檢測顏色的圖像識別庫
- 17. PHP GD:用色調顏色乘以圖像顏色
- 18. Java顏色檢測
- 19. Ghostscript顏色檢測
- 20. 檢測iDevice顏色
- 21. 硒 - 檢測顏色
- 22. Java顏色檢測
- 23. PNG圖像Alpha顏色問題用PHP
- 24. 使用C#進行顏色檢測
- 25. 使用opencv皮膚顏色檢測
- 26. 使用YCrCb顏色空間進行顏色檢測?
- 27. 使用javascript檢測顏色是否在兩種顏色之間
- 28. Python - 檢查圖像中心的顏色
- 29. java中的圖像處理和顏色檢測
- 30. 檢測某些顏色的矩形圖像
這可能是你的東西:http://stackoverflow.com/questions/3468500/detect-overall-average-color-of-the-picture – samn
感謝,多數民衆贊成真棒。你能把它當作答案嗎? – Tech4Wilco