How to make a color transparent in Gimp

Background: I was working on some images of a mobile phone, and the mobile phone was surrounded by a solid color that I wanted to make transparent. Unfortunately the phone was black, and that color was dark gray, so when I made the dark gray a transparent color in Gimp using my usual approach — clicking Colors > Color to Alpha, then choosing dark gray — it had the effect of bleeding a lot of color out of the black phone. This was wrong.

Solution: Gimp color to alpha with no bleeding

After a little research I found this solution on the StackExchange website, which is close to what I needed:

(I made a few notes on that image to help me remember what I did.)

An example: Black phone with a gray background

My own images were of a black Android Nexus 5 emulator on a gray background, which looks like this:

What I did to implement the Stack Exchange instructions was this:

  1. Load the original image into Gimp.
  2. Click the Color Select tool.
  3. In the Tool Options, make the threshold zero.
  4. Choose the “feather” option. (Experiment with the Radius setting, but start with the default value.)
  5. Add transparency to the image (Click Layer > Transparency > Add Alpha Channel.)
  6. Click the background gray color. This implements the "color select" tool, and you should see some moving highlights around the borders of the color you selected, indicating that every pixel that is of that exact color is now selected.
  7. Click Edit > Clear.

After doing this I still had to do some erasing work in the gray background area, but this technique deleted probably 90-95% of the gray color properly, without pulling any color out of the black phone, which is very important. (You can also work with the “threshold” to see if this makes the selection/clearing process better, without bleeding any color out of the main object in your image.)

This is what the same image looks like immediately after I follow the transparency steps described (without any other cleanup):

As mentioned, modifying the “threshold” to just 2.0 gets rid of almost all of those extra spots:

I tend to be very careful with that setting, as I don’t want to remove any color from my main object -- the black phone, in this case, but those two images show how much that setting can help you.

Bug

Note that there seems to be a bug in Gimp 2.8 where trying to use this technique more than once does not work. This doesn’t always happen, I can’t figure out exactly how to repeat the bug, but if you find that this technique doesn’t work after you’ve used it the first time, the thing I’ve learned to do is to close Gimp and then restart it.

Summary

If you ever need to make a color transparent in Gimp -- without bleeding any color out of the main object in your image -- I hope this technique is helpful.