Change one colour to another?

116

21

In GIMP, I have a green button GIF image: it shades from dark green to light green, against a transparent background. I would like to change it to blue, and keep the shading, so it shades from dark blue to light blue.

How can I do this?

AP257

Posted 2010-06-16T15:23:02.953

Reputation:

Answers

86

If you load a GIF image, you likely have a paletted image. Make sure to change it to RGB first with: ImageModeRGB. Changing colors (including resize operations) won't work very well with palettes because Gimp limits its selection of colors to the colors defined in the palette.

I suggest rotating Hue in ColorsHue-Saturation.

Given an initial image like this:

green gradient

You change Hue first by clicking on Master and then dragging the Hue slider and then adjust Brightness and Constrast to your liking.

Adjust Hue in Colors -> Hue-Saturation

The result looks like this:

blue gradient

You can easily make it colder or warmer, darker or lighter, more or less saturated.

sastanin

Posted 2010-06-16T15:23:02.953

Reputation: 3 537

1What if I want to change the image to a given RGB value? – Aaron Franke – 2018-12-20T20:25:17.097

3Good answer. As an added note, if your button contains a border this will change it's color as well. To avoid this use the selection tool to only select the area you would like to recolor, then run Hue-Saturation. – Lee Harrison – 2014-02-05T16:15:11.243

79

If you are using GIMP 2.8.2, you can simple use Colors -> Map -> Color Exchange.

Source: How can I swap colors with GIMP?

Patricio

Posted 2010-06-16T15:23:02.953

Reputation: 891

3I'm looking for a mathematical transformation. I'm converting #650000 to #590000, so I feel like I should be able to apply -060000 to every pixel, but I don't see any easy way... – isaaclw – 2015-07-02T04:19:01.077

You can also use "Colors -> Map -> Gradient Map" to change gradients. Very useful – Javier Constanzo – 2016-06-15T17:34:00.197

2That's the answer. By adjusting the threshold, one can also handle the tones of the color (for example in case of anti-aliased character boundaries) – Csaba Toth – 2017-02-03T22:23:59.357

Also note the image mode must be set to RGB for the Color Exchange option to be enabled – dspacejs – 2018-04-04T02:22:07.840

2This also only seems capable of operating on a clicked region of contiguous pixes, not on all of the selected pixels. Like I commented above, this colorizes the pixel I invoke it on. The Select by Color has selected hundreds of pixels all over the image. – ProfK – 2013-03-23T10:39:24.000

3@ProfKaos It works fine for me. In case I have nothing selected, Color Exchange changes all the pixels in whole image. – MasterPJ – 2013-04-17T10:40:33.133

22

You're looking for menu Colors, and especially the function Colorize.

Bobby

Posted 2010-06-16T15:23:02.953

Reputation: 8 534

3That only colorizes the pixel I invoke it on. The Select by Color has selected hundreds of pixels all over the image. – ProfK – 2013-03-23T10:37:02.223

1Does that keep the shading, resulting shades from dark blue to light blue? – Peter Mortensen – 2014-02-19T10:34:13.047

8

To change a color to another specific color to I suggest to use Colorify.

Suppose we want to change the blue color (#05adee) of the superuser logo into a green color near to #05ad27.

  1. ColorsColor to Alpha: choose the secondary color which will be made transparent (white in our example)

enter image description here

  1. ColorsColorifyCustom color: choose the destination color and add about 10-40 to the Value (of the HSV)

enter image description here

  1. Set the secondary color as background color (white in our example)
  2. ImageFlatten Image

Using GIMP 2.8.6.

Marco Lackovic

Posted 2010-06-16T15:23:02.953

Reputation: 506

This makes my image much darker than it should be. Is there a way that I can replace one color gradient with another color gradient? – Aaron Franke – 2018-12-20T20:27:48.293

1Does that work with a shading, shades from dark blue to light blue? – Peter Mortensen – 2014-02-19T10:25:23.180

1Yes. If you zoom in the two samples I posted you will see the shades are properly changed. – Marco Lackovic – 2014-02-19T11:16:00.707

5

The first successful method I found to do the same sort of thing was to use ImageMagick, but with a different operator than the earlier-suggested --separate/-swap.

The different operator is either -recolor or -color-matrix, depending on ImageMagick version.

Specifically, because I knew a "master color" of the original image (green, in your case and mine) and I knew the "master color" in the desired result image (blue, in your case, orange in mine), I gave ImageMagick' -recolor/-color-matrix option a transformation matrix with values that reflected the differences in each of the RGB channels.

For example, in my case, the fully green color was R:141 G:198 B:63 and I wanted it changed to R:231 G:159 B:70. The rest of the colors wanted to be changed equivalently.

So that means I wanted new pixels' R value to be 231/141ths of the current red value. Green values to be 159/198th of the current values. And blue values to be 63/70ths of the current values.

So:

convert input.png -recolor      "1.638297872 0 0    0 0.803030303 0   0 0 1.111111111" output.png

or

convert input.png -color-matrix "1.638297872 0 0    0 0.803030303 0   0 0 1.111111111" output.png

or

This seemed to work in a flash after fruitlessly spending a lot of time wrestling with Gimp/plugins and paint.net/plugins.

Alex Robinson

Posted 2010-06-16T15:23:02.953

Reputation: 151

3

  1. Change your foreground color to your desired color. (for example blue in your case)
  2. Change Background to white or something
  3. Open gradient tool and set FG to BG or FG to transparent.
  4. Select area or Color using 'Select by Color'
  5. Colors -> Map -> Gradient Map

roel

Posted 2010-06-16T15:23:02.953

Reputation: 131

2

If you update the HUE with an existing image color the hue will be initiated with those levels... Need first to make a white #fff background. I did

Colors -> Colorize and set the HUE lightness to 100... this will remove any color from your image.

Then You can use Colors -> Colorify and apply the color You want.

mario ruiz

Posted 2010-06-16T15:23:02.953

Reputation: 283

2

I don't know how to do it in GIMP, but ImageMagick has functions to separate and combine color channels. See this page.

I was able to convert a green GIF file to blue with this command:

convert input.gif -separate -swap 1,2 -combine output.gif

I guess that 1 and 2 refer to green and blue channels, 0 is red.

W_Whalley

Posted 2010-06-16T15:23:02.953

Reputation: 3 212

1

On simple small graphics, I zoom in a lot and then change the colors myself using the brush.

Just change the brush size to 1 pixel.

Ed B

Posted 2010-06-16T15:23:02.953

Reputation: 119

4-1 That's not practical if there is a gradient, you'd have to change dozens of different colors. – sleske – 2012-03-30T09:38:24.573

1The two Gimp solutions given so far above aren't much better, so it looks like I'm stuck with it. – ProfK – 2013-03-23T10:40:56.287