Zanic L3
Zanic L3

Reputation: 1088

PHP - Filter/search on colours

enter image description here

I'm now able to extract colours from a picture, but now I want to be able to search/filter on a colour; similar to what you can do on Dribbble and other sites. How can I create this?

Insert the colours codes into a new table colour in the DB when creating a new post and linking the post_id? Or?

I've used the following answer to extract the colours.

https://stackoverflow.com/a/3468588/7278089

Upvotes: 1

Views: 358

Answers (1)

david
david

Reputation: 633

Yes, you could create a table that links images to colors.

colour_id colour_code
1         #666666
2         #CCCCCC
...       ...

post_id colour_id
1       1
1       2
2       3
...     ...

You probably want to normalize the color codes in your search input (e.g. transform #666 to #666666), because your users might expect that.

Also it might make sense to group colors into groups like light blue, dark grey, etc. A user might not always know the exact color code of the colors in the image he/she is looking for. You could create another table for mapping color codes to groups, like colour_code_to_group, and then map posts to groups instead of (or in addition to) color codes.

Upvotes: 1

Related Questions