Kevin Old
Kevin Old

Reputation: 1029

Shift hue on existing image(s) via imagemagick -modulate from Photoshop Hue/Saturation values

I am trying to shift the hue of this image (and others like it) with varying gradients, etc from the "blue" to another color as defined by my designer from the mockups done in Photoshop.

I've attached 2 Hue/Saturation screens from Photoshop with HSL values for purple and orange but using -modulate in Imagemagick via this ruby code:

# burnt orange - works
hue = 25.0 # must be a decimal
sat = 100
bri = 0

# purple - does not work
#hue = 266.0 # must be a decimal
#sat = 100
#bri = 0

# formula from -modulate http://www.imagemagick.org/Usage/color_mods/#modulate
h = ( hue * 100/180 ) + 100

system("convert -define modulate:colorspace=HSB home_tab_back_right.png -modulate #{h},#{sat},#{bri} #{h}-#{sat}-#{bri}-home_tab_back_right.png")

This will work for the burnt orange image, but not for purple and other colors I've been given.

I have had more success by passing "modulate:colorspace=HSB" than without, but still not able to consistently plugin values received from Photoshop and have it take the base blue image and shift the hue.

Can this be done?

base blue image I would like shifted to another color

burnt orange hue saturation from photoshop

purple hue saturation from photoshop

Upvotes: 3

Views: 3539

Answers (1)

xke
xke

Reputation: 1093

I noticed a bug in the above code. The ImageMagick "-modulate" option actually expects the numbers in the order of: $brightness, $saturation, $hue.

I needed to turn "original.png" images in subfolders from the original Blue color, to Red and Green versions.

This is what I used for Red:

for dir in *; do convert -define modulate:colorspace=HSB $dir/original.png -modulate 100,100,180 $dir/original_red.png; done;

This is what I used for Green:

for dir in *; do convert -define modulate:colorspace=HSB $dir/original.png -modulate 100,100,270 $dir/original_green.png; done;

Note that in above, I kept the Brightness and Saturation the same as original (100) and tuned the Hue (180 for Blue > Red, and 270 for Green > Red).

Hope this is helpful!

Upvotes: 5

Related Questions