home of the madduck/ blog/
Removing background from images

Every now and then, I want to remove the background from an image and replace it with transparency. Instead of painful pixel work with the select tool, the following Gimp recipe does the job quite well, provided the background is a single colour:

  1. Choose Layer->Transparency->Colour to Alpha and select the background colour in the dialog box. Then click OK.

  2. Use the magic wand tool (Z) to select the contiguous region around your object. Make sure to use a sufficiently high threshold such that the selection line coincides with the image's silhouette.

  3. Press Ctrl-I to invert the selection.

  4. Choose Select->Shrink and shrink the selection by a pixel or two.

  5. Create a new, transparent layer. The selection should still be active.

  6. Make the background colour you previously converted to transparent your foreground colour and choose Edit->Fill with FD Colour from the menu.

  7. Switch the two layers such that the current one moves behind the one containing your image.

The method isn't perfect, but it certainly saves me a lot of time. For instance, my new hackergotchi — a tribute to Scotland and the local team of DebConf7 — only took me a few minutes to get ready.

Suggestions still welcome.

NP: Barclay James Harvest: Everyone Is Everybody Else