Replace/change/shift colors

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mideal
Posts: 3
Joined: 2017-03-13T06:07:11-07:00
Authentication code: 1151

Replace/change/shift colors

Post by mideal »

Hi1
While changing a (Linux Mint 18.1 Cinnamon) theme a encountered a folder with 50+ png files with buttons and such things.
There are all in varaitions of mintish green of different brightness (for checked/unchecked, presses/release...), and I like to change all those with a batch command to similar variations blue.
Easy replacement isn't possible because of the different shades of the source.

I found this (to change from green to red):

Code: Select all

convert some_image.jpg \( +clone -channel G -fx R \) +swap -channel R -fx v.G swapped.jpg
here: http://www.linuxquestions.org/questions ... ost5682829, changing it to

Code: Select all

convert checkbox-checked-dark@2.png \( +clone -channel B -fx G \) +swap -channel G -fx v.B swapped.png
results in a quite violet touch.

Any suggestions?
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Replace/change/shift colors

Post by GeeMack »

mideal wrote: 2017-03-13T06:21:51-07:00There are all in varaitions of mintish green of different brightness (for checked/unchecked, presses/release...), and I like to change all those with a batch command to similar variations blue.
It may not be exactly what you want, but you can use the "-modulate" operator to more or less roll the colors around the wheel. The operator takes up to three arguments. The one you want to adjust for color shifting is the third. A command like this should give you an idea what it can do...

Code: Select all

convert input.png -modulate 100,100,50 output.png
That third argument, where I used a value of 50, can take any number from 0 to 200. Use 100 for no change, and higher or lower values to shift around the color wheel. You can learn more about color modifications at THIS link.
mideal
Posts: 3
Joined: 2017-03-13T06:07:11-07:00
Authentication code: 1151

Re: Replace/change/shift colors

Post by mideal »

It seems that you have to try a bit with one or two examples to get the expected result color.
90,180,170 gives me the nice blue tones I wanted for all shades in the theme.

Thank you!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replace/change/shift colors

Post by snibgo »

Yes, K as well as the first three channels (RGB or CMY). I work almost exclusively with RGB, so I usually forget about the K channel.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Replace/change/shift colors

Post by anthony »

I recommend modulating in a different cyclic hue colorspace such as LCHab as it will preserve the color intensity better, though the hue values are slightly different.

See Modulate in LCHab and other Colorspaces
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply