Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - get color name from rgb

Tags:

php

colors

gd

i work now with GD library on PHP and i'm trying to get the pixel color name ,i mean : green , red , blue , etc...

i'm getting the color this way :

$rgb = ImageColorAt($image, $X, $y);
$r = ($rgb >> 16) & 0xFF ;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;

now , how can i find it this color is green light , dark blue , normal blue or red and etc..

like image 316
homerun Avatar asked Sep 29 '11 16:09

homerun


2 Answers

you have to create an associative-array that maps value => colorname (or inverse). fill this array with the data of this table: http://en.wikipedia.org/wiki/Web_colors

then you can lookup the color names, that are available in CSS too. additionally you can add more, own, colornames

like image 101
0xDEADBEEF Avatar answered Sep 24 '22 02:09

0xDEADBEEF


Are you suppose that every color has its own name?
It's 16^6>16.7 millions.

So, it seems to be impossible.
But you may create your own database (format rgb => human-readable)

like image 33
RiaD Avatar answered Sep 25 '22 02:09

RiaD