How to replace a color in the image using js or php?

Hi all. There are images of carpets on which you want to replace the color with js or php, but to preserve the texture. OpenCV does not see the edge of the picture or in neither hsv to rgb as the colors are very similar.
or I not so do something, but when you choose orange in the sample gets yellow. As gray enters with a dark gray. In the photo 5 colors.
Tell me how using a library for js that you can implement.
For clarity, the attached example:
April 4th 20 at 00:45
1 answer
April 4th 20 at 00:47
Hi, try using css and hue-rotate:'hue-rotate(45deg)'

Find more questions by tags PHPJavaScriptOpenCV