You can get picture histogram in PHP. You can find more info and code example here: http://php.net/manual/en/imagick.getimagehistogram.php
To map your color to html name, you can go through the array of colors and calculate color distance with color you are looking for. The color with the smallest distance is the one which will give the best html name. You can find more resources about color distance here: https://en.m.wikipedia.org/wiki/Color_difference
This might take huge amount of time every time you process every new picture so BETTER SOLUTION:
You are in RGB color space. This means you have 256x256x256 different colors. Each color is defined by RGB coordinates - http://www.w3schools.com/colors/colors_names.asp. For examle 'aqua' has RGB coordinates (0,255,255). Your goal is to name all colors in RGB space by a name, but you dont need unique name for very single color in RGB space because you are not able to distinguish every detail by your eye (for example (0,0,1) and (0,0,2) would look the same). Therefore you specify a list of color names you want:
$colorNames = array(
[0] => 'white', //#FFFFFF
[1] => 'red', //#FF0000
...
);
Now, for quick mapping of color C, given by coordinates (r,g,b), to color name, you have to lookup, what index in $colorNames array corresponds to color C. For this, you can prepare a file in advance, which has size of 256*256*256 = 16MB. Each byte represents one point in RGB space. The value of the byte is the index of color in $colorNames array to which the color is similar the most. How to create the file (pseudo code):
for every value of R coordinate
for every value of G coordinate
for every value of B coordinate
find which color name in $colorName has the smallest distance to coordinates (R,G,B)
store the index for this color name to file
Now you have file which holds all indexes for any color. This means that all you have to do now, to map any color to name, is read one byte in this file and look into the array for the name of the color.
open mapping file
read one byte on position (R*256*256 + G*256 + B)
this byte is the 'index' in colorNames array
read the color name (colorNames['index'])