开发者

How can I store HTML color codes in a MySQL database then search for a range or colors?

开发者 https://www.devze.com 2022-12-21 04:46 出处:网络
I have a script that extracts the mostly commonly occurring colors from an image. I want to store this data in MySQL then be able to pull out images based on the clicking of a color. For example if th

I have a script that extracts the mostly commonly occurring colors from an image. I want to store this data in MySQL then be able to pull out images based on the clicking of a color. For example if the user clicks on a red color I want to pull out other images that have a high count for "red" colors. I'm not开发者_JS百科 sure how to search within a range of color values or what values to actually store in the database. Ideally I'd like to present the user with a gradient band and have them click on it to find images that are close in color to what they clicked.

Any help, pointers, or keywords I can used to Google for more information would be userful.


Take a look at my answer to this question. Basically you store the hex values of each component separately, then you can search for them with a simple mySQL query. I suppose yo could populate a table by iterating every color in an image and putting in the top x colors to the table.

select imageName from imageColors where ( ABS(red - $redHex) + ABS(blue-$blueHex) + ABS(green - $greenHex) < $threshold)

$threshold is the maximum distance between the colors.


My first thought is that your best bet is to use 6-digit hex, and store each component (red, green, blue) in a separate field.

Looking for something "red"? Select those records with a high red count, and relatively low green and blue, and then be ready to tweak your cutoffs.


There's a class on PHPclasses.org that promises to find the "dominant colour." Haven't used it myself so I can't say anything about its quality but it has been reviewed by PHPclasses, which usually makes it worth checking out.

0

精彩评论

暂无评论...
验证码 换一张
取 消