views:

35

answers:

2

I'm working on a simple image gallery project and I'd like to implement the ability to search based on a color hex code. So if someone enters 'ff1212' into the search, it will display only those images that contain that particular shade of red. I've seen a website that has a search that works the way I want: http://cssline.com (the AJAX part is nice, but its the server-side stuff I'm after).

I can't figure out how to store the color data from each image. Should I get each unique hex code used in an image and store them as tags in a database? It seems like this would create a huge dataset which would slow down the search. What about storing the images themselves in the database and scanning their colors during the search? That also sounds like it would be slow. I know that once I figure out how to store the data for speedy searching I can figure out how to code the search itself.

Does anybody have any tips or advice that can help me?

A: 

You may try storing color intervals of each image in a database rather than storing each unique color value. Of course, searching these intervals may require a different search algorithm.

erelender
I'm not sure I understand what you mean by color intervals. How would that data look in the database?
James
A: 

I dont think that storing color values in database will make it slow. It will, although, make it insanely large! And given that you can index data on color values, the process will be fast.

Mayank
So if I store the color hex codes as if they were tags using a link-table then the queries can still be fast even though there can potentially be hundreds or thousands of colors per image?
James