E
E
ErickSkrauch2014-10-21 18:58:28
PHP
ErickSkrauch, 2014-10-21 18:58:28

How to store and look up color in MySQL?

Hello. There is a task, after the user selects the main color of the image, to save it to the database, and then perform a search by shades of this color (well, that is, close in value, exactly there will be units).
I'm going to use simple math and rgb format manipulation, but I have no idea how best to store the color in the database so that I can somehow look for it. 3 columns is a bad idea (IMHO), a long integer is impractical, and the hex format in mysql is only saved as a string, because it doesn't know how to use hexadecimal numbers.
Basically, I need an idea.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-10-21
@ErickSkrauch

If you need to search by hue, it would be more logical to convert RGB to HSV (Hue, Saturation, Value) and search for the HUE (hue) component. And no math in queries, indexes are quick and easy. In general, RGB is not well suited for the task of finding a color. It is well understood by the video card and monitor. Printers here also do not like RGB, they like cmyk more.
And although I am against RGB for such a task and in general for storing it for elections ...
3 TINYINT columns and all unsigned. This is 3ubyte. Three value [0-255]. Exactly what is needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question