Help

Converting hex values to the nearest color name

Topic Labels: Formulas
4024 11
cancel
Showing results for 
Search instead for 
Did you mean: 
Vignisson
5 - Automation Enthusiast
5 - Automation Enthusiast

does anyone know a way to convert hexadecimal values to actual color names (or the nearest neighbour).

Examples:
#ffffff = white
#eeeeee = light grey
#45c1f6 = light blue

11 Replies 11

I would check out the color palette app!

I have. It does not convert hex codes automatically, by formula, into color names. What I need is to take hundreds of items and automatically detect the primary color of each item (I have done already that with miniExtensions) and render the resulting hex value out as the official “HTML color name” in a seprate field.

What about hex colors that do not have an official html/css name?

You could use a very long switch statement for the most common colors, but there are too many possible color to include every color.

That is exactly the dilemma, there are way too many options, hence the “(or the nearest neighbour)”. Ideally 12-15 main colors would do the trick. The purpose is to automatically generate “filter by color”, information that would help to filter those items in online store.

I hope you’re not trying to do this in a formula field.

This is the javascript code you want and it will work in a Script Block or a Script Automation. And if Airtable would simply make it possible to call script apps as functions, it could also be a formula. [sigh]

To add to @Bill.French’s JavaScript solution, here’s a reference table you could add to your base for creating cross-references:

Data courtesy of XKCD and Stitch Fix.

This is very cool - and doesn’t this mean you could use a formula to perform the lookups pretty easily?

I think you could with exact matches, at least — of which there is the possibility for many. However, if “nearest neighbor” matching is still needed beyond the scope of the colors provided here (I’m sure there are millions of actual potential hex-color outputs), there will still be a need for JavaScript. But having all these color references may provide a richer data set for that JavaScript to operate on.

But it’s also possible there are simple rules that govern how hex codes map to color outputs that could be expressed in a JavaScript algorithm — if so, I don’t know what those rules are. :man_shrugging:t2:

I just happened to be in possession of this, rather large, color data set, and discovered this post. Thought it might end up being useful for something here.

URTM @Bill.French. I didn’t dare to start playing with this as a formula :winking_face:
Now as a non-coder this looks like Spanish to me. You know, I can manage to order a chicken in Barcelona by looking at the pictures on the menu and then figure out some key words to tell the waiter. :upside_down_face:
But this really helps to get closer to the solution, I’m sure. I will have one of my friends having a look at it and see if we can figure out how to take advantage of the code. Thank you so very much for taking your time to find it and share with us!