Are the images saved in your database? If so, give them an attribute that is a color and match off of that. If not, then the conditionals will do what you need but it will be more work.
I would probably make an Option Set of all possible color options. Then give each image an attribute that has a type of the color option set and make the custom state on the page off the same option set. That way the source for the image can be a search for the image where the color attribute equals the custom states color option.