How can I detect the top 2 colors of an Image in PHP?
for example I have this image:
This function/process will return: 0000FF or blue and FFFF00 or YELLOW
Thanks
How can I detect the top 2 colors of an Image in PHP?
for example I have this image:
This function/process will return: 0000FF or blue and FFFF00 or YELLOW
Thanks
If you are OK to call an external utility, Imagemagick can generate a histogram for you. It's probably going to be much faster than a PHP implementation.
Basically, this command gives you a list of colours, sorted by most dominant first:
You might want to map the image to a fixed palette first ("Round off" the colours). This is what I use:
Here's a script that will give you the list: