Hi there, I'm Matt and would like to help you (23 year an IT pro and a webmaster, graduated with digital image processing and recognition).
You have a "classical" problem of the so called image segmentation - finding all areas with similar colors (and do something with them). The image segmentation algorithms are several and using them depends on the classification wish (what to segment in the image).
So:
1. Can you provide some images you want to do image segmentation on?
2. Do most of the images have small number of similarly colored areas?
3. What colors do you want to distinguish (like 4, 8, 12 most used etc)?
PHP has only one image segmentation function that can help (find edges of areas) while everything other has to be custom scripted (like marking areas, counting pixels, "thresholding", writing numbers e.g. counters of pixel areas etc).
Looking forward to your reply. I can do that in next days.
Regards,
Matt