Replace color in a gif using imagemagick or GIMP

I'll start out with a disclaimer. I hate GIMP, I absolutely truly do. I love Paint.NET. I love Krita. I hate GIMP. It's as simple as that. Take a look at The Design of Everyday Things for reasons as to why GIMP sucks. One cannot define the conceptual model for it. It is not apparent how to use. This complex design drives users away in droves. The first part will be how we do this in GIMP and then the second part how we do this using ImageMagick.

That said, unfortunately Krita doesn't have gif support and I can't use Paint.NET on my Ubuntu box. At least not without a lot of extra effort and software. So, back to GIMP it is.

So we have a GIF with a transparent background, some text, some other assorted colors. We want to replace the color of the text. Simple, from the menu choose Select -> By Color. Then click on the text of the color you are replacing. Then, click on the fill button (the paint bucket), select a color, and fill that text back in. Sounds simple right?

Well no, actually. What if your color is not available, say you need some fancy gold color. Ok well you can add it in the fill color dialog, using the HEX or RGB values. Great! Now, you got to paste the color in. But wait! That's not the color I chose! What's going on here? What's happening is, the color doesn't actually exist in the palette so GIMP is choosing the next closest color available. Too bad it couldn't let us know that. How can we get the color we want. Well you need the palette dialog. What can't find the palette dialog? Well, perhaps you went to the GIMP docs. However, make sure you go to the right version of the docs, cause of course how to get to the dialog has changed, cause GIMP likes to changed the interface on users, often. Open the dialog using Windows → Dockable Dialogs → Palettes; From there you can then edit the dialog to add a color for the magic gold you want, say e2af2d. You can choose any spot 1-255 for it, I just put it in 255 over the white and it seemed to work ok. Finally, save your image and there you have it.

We could also try this using ImageMagick on the command line if we have it installed. Try "convert" on your command line. If it is installed you will get a list of options. Using the convert command we can do neat things like "convert image.png image.gif" and then we have converted a gif to a png simply and quickly. Granted, you have to worry about alpha channels and transparency in some cases, but you get the idea. Now, if we want to replace a color we can do something like "convert image.gif -fill "#eeeeee" -opaque "#e2af2d" image2.gif" Now, unfortunately, since the color isn't in the palette this still won't work out to great for us if don't have the color in the palette so you will still need to do that with GIMP unless you know the command to do it. I suspect this post this post may hold the key, but I haven't figured it out yet. Hope that helps someone out there trying to convert colors in a gif.

Comments

Thank you for saving my day!

Exacly the answer I was looking for, thanks for the explanation.
/Henrik

GIMP how-to

1. Select from the menu: Windows → Dockable dialogs → Colormap
2. Double-click the colour you want to change; or select it then push the Edit color button
3. Use any method to input the new colour you want: HTML notation, colour wheel, pick from palette…

At least on my GIMP 2.6.9.

If your file's palette has too many colours (maybe 256 and you're only using a handful, happened to me), then:
1. Image → Mode → RGB
2. Image → Mode → Indexed…
3. Play around with the options. If all colours are web-safe, choose "web-optimized" and "remove unused colours".

Peace,

Ttz.

My ImageMagick version (6.4.0

My ImageMagick version (6.4.0) is intelligent enough to handle color changes and update the GIF palette automatically. So your proposed command

convert image.gif -fill "#eeeeee" -opaque "#e2af2d" image2.gif

works fine. Thanks!

gimp sucks

after trying to figure out how, in gimp, to select an area of my image and move it around I gave up. I managed it in krita but i actually found this website by searching for how to replace a color in krita - so neither programs seem that intuitive to me. I grew up using paint shop pro 7 on windows and found that easy from day 1 :(

I don't think anyone truly

I don't think anyone truly loves GIMP, but the price is right. I can't imagine paying hundreds or thousands of dollars for Paint Shop Pro. That said, Adobe has a new subscription based pricing model coming out, which could make it worth it to switch back

Add new comment

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Comment using an existing account (Google, Twitter, etc.)