Depends mainly on the complexity of the image and the amount of colors in the palette.
If they are already pre-established colors, and the product image has many details, I believe it is more feasible to use different images of the product, a p/ each color.
But there are several solutions to apply color programmatically.
If the image is in vector, you can easily do it with SVG and jQuery. You can export, for example, an SVG Illustrator image and manipulate the elements with jQuery p/ change colors.
Here has a post explaining how to do this using Canvas and Javascript, with this example related.
This jQuery plugin looks pretty interesting.
To select the color through a palette, there are several jQuery plugins.
This may be what I need: http://sandbox.nikorablin.com/productColorizer
– Marcos Vinicius