# How to get hex color code from the image

I want to build a function which will work like this website: http://imagecolorpicker.com/

I'll upload the picture and get the hex or RGB color code of the color on the image, how is it possible?

For example I have this image I know, it's hex code is #FF5733, how can I make Mathmatica define color for me?

• If Mathmatica doesn't work with Hex colors, can I do same stuff with RGB colors? – Artem Anisimov Jan 17 '17 at 20:35
• What that site does correspond to PixelValue[image, pos] in wolfram – Coolwater Jan 17 '17 at 20:57
• Note that if you load an image into Mathematica and then right-click on it, you'll see "Get Pixel Color" among the options. – J. M. is away Jan 18 '17 at 19:12

Import image:

img = Import["https://i.stack.imgur.com/dApi1.png"]


Assuming all pixels are the same, grab the RGB data from the first one:

id = ImageData[img][[1, 1]]*255


Hexify:

StringJoin["#",


"#ff5733"

Wrap it in a function (this time finding "commonest" pixel)...

gethex[img_?ImageQ] :=
Module[{id = Round[Commonest[Join @@ ImageData[img]][[1]]*255]},

• @ArtemAnisimov, that's what the second step (id) does above. – kale Jan 19 '17 at 15:31