php无法获得最接近的匹配颜色
我需要帮助从一组预定义颜色和单个随机颜色中找到最接近的颜色匹配,这是我的代码:
color = array('124','197','118'); // LIGHT GREEN
$match = array(
array('255', '000', '000', 'FF0000'), //red
array('000', '255', '000', '00FF00'), //green
array('000', '000', '255', '0000FF'), //blue
array('0', '255', '255', '00ffff'), //cyan
array('117', '076', '036', '754c24'), //brown
array('000', '000', '000', '000000'), //black
array('149', '149', '149', '959595'), //grey
array('242', '101', '034', 'f26522'), //orange
array('245', '152', '157', 'f5989d'), //pink
array('255', '255', '000', 'FFFF00'), //yellow
array('102', '045', '145', '662d91'), //purple
array('255', '255', '255', 'FFFFFF')); //white
echo 'Color: <div style="background-color:#'.$color.';width:25px;height:25px"></div>'; //color
foreach($match as $co) $temp[] = array( sqrt(($color[0]-$co[0])^2+($color[1]-$co[1])^2+($color[2]-$co[2])^2) , $co[3]);
asort($temp);
foreach($temp as $ta) { echo 'Matched Color: <div style="background-color:#'.$ta[1].';width:25px;height:25px"></div>'; break; }
它返回灰色而不是绿色?我该如何解决这个问题?比
I need help finding the closest color match from a set of predefined colors and a single random color, here is my code:
color = array('124','197','118'); // LIGHT GREEN
$match = array(
array('255', '000', '000', 'FF0000'), //red
array('000', '255', '000', '00FF00'), //green
array('000', '000', '255', '0000FF'), //blue
array('0', '255', '255', '00ffff'), //cyan
array('117', '076', '036', '754c24'), //brown
array('000', '000', '000', '000000'), //black
array('149', '149', '149', '959595'), //grey
array('242', '101', '034', 'f26522'), //orange
array('245', '152', '157', 'f5989d'), //pink
array('255', '255', '000', 'FFFF00'), //yellow
array('102', '045', '145', '662d91'), //purple
array('255', '255', '255', 'FFFFFF')); //white
echo 'Color: <div style="background-color:#'.$color.';width:25px;height:25px"></div>'; //color
foreach($match as $co) $temp[] = array( sqrt(($color[0]-$co[0])^2+($color[1]-$co[1])^2+($color[2]-$co[2])^2) , $co[3]);
asort($temp);
foreach($temp as $ta) { echo 'Matched Color: <div style="background-color:#'.$ta[1].';width:25px;height:25px"></div>'; break; }
It returns grey instead of green? How can I fix this problem? Than
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里是一个匹配问题及其答案的链接:
RGB to 最接近的预定义颜色
但是,如果您已经有索引图像,我建议使用它:
http://php. net/manual/en/function.imagecolorclosest.php
here is a link to a matching question with answer:
RGB to closest predefined color
but, if you have an indexed image already, I suggest using this instead:
http://php.net/manual/en/function.imagecolorclosest.php
我把你的颜色放入我的 颜色转换器来分析您的问题。我想你可以看到灰色也是视觉上最接近的搭配。
我认为三色 124/197/118 不是浅绿色,但最重要的是一种不饱和的绿色,这解释了结果。
我不确定你的一些颜色定义。对我来说
如果您仍然不喜欢结果:
或者
I put your colors into my color converter to analyze your problem. I think you can see that gray is also the colosest match visually.
I think the tripple 124/197/118 is not a light green but foremost a desaturated green which explains the result.
I'm not sure about some of your color definitions. For me
If you still don't like the result:
or