tags:

views:

47

answers:

1

I create template websites. If a client choose a blue or green or purple heading, I don't want to have to store all those different color variations of an image. I want to programmatically change the hue. I do not want to 'flood fill' it because that would remove any textures or bevels.

For example page you see I have accomplished exactly what I want. http://sta.oursitesbetter.com/test/index.php

I have done this using Imagick modulateImage function.

HOWEVER, I am just throwing random 'Hue' values and not RGB values. I want to accomplish this same thing feeding RGB values. I need a function similar to modulateImage however it must take RGB as value and set the image to that hue.

I have studied for the past 5 hours and cannot figure out how to do it. I need help.

Has any of the guru's of StackOverflow got a PHP Imagick solution to this color quandry?

Jay CompuMatter

+1  A: 

From Wikipedia: Hue #Computing hue from RGB:

\tan h_{Preucil\ hexagon} = \frac{\sqrt{3}\cdot (G - B)}{2\cdot R - G - B}

$hex=(sqrt(3)*($green-$blue)) /
       (2*($red-$green-$blue));//$red, $green and $blue are each a value in the range 0->255


$img->modulateImage(100, 100, intval($hex*100/256));
//probably 256->100 value above will work, if didn't , try with the following insead.
//$img->modulateImage(100, 100, $hex);
aularon
Thank you. Conceptually it seemed to have promise but in practice it returned complete a black image in both cases.
Jay Lepore
Have you attempted this?
Jay Lepore
@Jay No, but now I'm interested to try it, I'll do a check after a while with some debugging to see if it works or need some modifications. (Your `$red`, `$green`, `$blue` are all `0->255` right? )
aularon
@Jay Edited, I have swapped parameters accidentally, now fixed.
aularon
Yes, my red, green, blue ->255Did you upload the code changes that are working?
Jay Lepore