342

I have some jpg images and I need for each of them to have a transparent background.

I have GIMP as a graphic tool.

I need to put them in a web page and I need to see just the main element and have a transparent background.

2
  • Just figured out if you're on a Macbook you have to press fn-delete after magic wand select ;) delete doesn't work by itself.
    – Ben
    Mar 28, 2016 at 17:45
  • Hey @Viola in GIMP v.2.10.18 the best way to do that is NOT by using a magic-wand tool. First you add an alpha-channel to your PNG (if it's png) with Layer > Transparency > Add Alpha-channel, then use Layer > Transparency > Color to Alpha... and it's magically done! Algorithms rule 🚀
    – magnump0
    Mar 20, 2020 at 9:26

4 Answers 4

344
+50

To expand on utopicam's answer, sometimes your image might contain areas, such as shadows, that you'd want to be semitransparent. For example, let's say you have a photo shot in a lightbox, such as this nice and freely licensed picture of a Swedish wooden toy horse courtesy of Creative Tools:

A photo of a Dalekarlian toy horse in a lightbox, licensed under CC-By 2.0 by Creative Tools

In general, the first step would be to adjust the levels of the image until the background really is solid white, except for the shadows and reflections we want to keep. (You can use this technique with a gray or colored background too, but it's a bit trickier to get good results that way.) In this case, the image is already nicely adjusted, so we don't have to do anything about that.

The next step is to select the background. This was quite easy to do with the magic wand tool, although I had to fix some bits where the white stripes on the object blend with the background with the lasso tool. Also, once I had the background nicely selected, I expanded the selection by a few pixels (at full resolution) to avoid leaving a whitish halo around the object due to aliasing. (You can't see it in this scaled-down screenshot, but I really managed to do a pretty nice job with the selection, if I may say so myself.)

Same picture with the background selected

Now, here's the trick: instead of simply cutting out the background, I used ColorsColor to Alpha to change the background color (white) to transparent. (You could also use bucket fill with the Color Erase mode as utopicam suggests.) If applied to the whole image, this would make the object look semitransparent too, but since only the background is selected, the shadows become translucent while the object itself stays opaque:

Picture after applying Color to Alpha

And here's the same picture on a pale blue background, to show the semitransparent shadows and reflections better:

Same picture on a pale blue background

One extra trick I didn't show is that it's often more convenient to make two copies of the image layer, convert the selection to a layer mask on the upper one, and apply Color to Alpha to the lower. This lets you fine-tune the edges of the object by editing the mask, while seeing live how the result will look. (Tip: make a few background layers filled with different colors, so that you can easily check how the picture looks on different backgrounds.) In particular, sometimes making highlights near the edges of the object just slightly translucent can make the result look nicer and more natural, since it mimics the background reflecting off the object.

4
  • 2
    the first step would be to adjust the levels of the image until the background really is solid white - should how to do this exactly be included for us dummies? Or should I ask a separate question on how to do that? Jan 13, 2013 at 1:49
  • 1
    @hippietrail: The levels tool generally does a pretty good job: just move the rightmost input slider left until it looks good, or use the white eye-dropper. If the cutoff looks too sharp, you can switch to "Edit these settings as Curves" and smooth it out there. (Basically, what you usually want is a curve that's mostly linear, but bends a bit near the top edge to meet it gradually rather than in a sharp corner.) Jan 13, 2013 at 5:45
  • 1
    I like the curves tool to move a "white" background up to full white. This also gives a nice histogram stretch across the rest of the image too.
    – Mr Purple
    Nov 1, 2016 at 21:45
  • 1
    @MaifeeUlAsad: I've reverted your edit. After testing in GIMP 2.10.34 (macOS arm64, DMG revision 2) I can confirm that the Color to Alpha… feature still exists and is accessible both under Colors and under Layer > Transparency. Aug 15, 2023 at 17:22
86

Using fast bucket fill instead of contour selection

Note: This tutorial is also available in PDF.

_La trahison des images_ by fellow countryman René Magritte; partly vandalised for the purpose of this tutorial.

Add an alpha channel

Some image types lack a transparency channel; JPG for example. If this is the case, add an alpha transparency channel. This is done by selecting Layer → Tranparency → Add Alpha Channel.

Bucket fill with colour [optional]

The next step is optional and consists in filling the area that should become transparent with a plain colour first. Select the bucket fill tool or hit Shift+B. Within the Bucket Fill toolbox options, select Fill transparent areas only when necessary. Do select BG colour fill and Sample merged and run a few tries while adjusting Threshold for best results. In between, hit Ctrl+Z to undo.

Some colour mixing will be inevitable and even desired. (In this respect, Adobe Photoshop is no different.) Hence, choose a colour which is compatible with the background on which the resulting picture will eventually be used. Click on the background colour rectangle in the upper half of the Tool Options toolbox window to change the background colour. Here, I used f3f3e9 as a background colour for plain colour filling. However, one can also use the eyedropper tool to pick a colour from anywhere on the desktop.

<code>Bucket Fill</code>:  Select <code>Fill transparent areas</code> only when necessary. Do select <code>BG colour fill</code> and <code>Sample merged</code> and run a few tries while adjusting <code>Threshold</code> for best results. In between, hit <kbd>Ctrl</kbd>+<kbd>Z</kbd> to undo.

<code>Bucket Fill</code> applied. Choose a fill colour which is compatible with the background on which the resulting picture will eventually be used. This is because some colour mixing is inevitable and even desired. Here, I used <code>f3f3e9</code> for plain colour filling.

Select by colour

The right thing to do now is Select → By Colour. It might be tempting to perform Colour to Transparency, however this would also change semi-transparent areas within the desired image area. This time around, do select Fill transparent areas as well as Sample merged. For this particular example I chose not to apply Antialiasing nor Feather edges. Nonetheless, do experiment with these settings and choose what looks best. Again, run a few tries while adjusting Threshold for best results. In between, hit Ctrl+Z to undo.

<code>Select by Colour</code>:  This time around, do select <code>Fill transparent areas</code> as well as <code>Sample merged</code>. Again, run a few tries while adjusting <code>Threshold</code> and experiment with <code>Antialiasing</code> and <code>Feather edges</code> for best results. In between, hit\ <kbd>Ctrl</kbd>+<kbd>Z</kbd> to undo.

<code>Select → By Colour</code> applied

Subtract from the selection

At times, it proves difficult to get the colour selection exactly right. Some of the desired image area might be selected as well because the colour matched. In this case, and barely visible, nine desired pixels in the middle of the pipe were also selected for deletion. When this happens, use Ctrl+Drag with a Select tool of your choice to select a subtractive selection area.

Use <kbd>Ctrl</kbd>+<code>Drag</code> with a <code>Select</code> tool of your choice to select a subtractive selection area.

The desired transparency area is now selected.

Grow the selection [optional]

At the rim of the desired image, some shades of the background my still remain unselected. If this is the case, grow the selection with a pixel using Select → Grow… → 1px.

Delete

Once the desired transparency area is selected, simply hit Delete.

Once the desired transparency area is selected, simply hit <kbd>Delete</kbd>.

Final result

Finally, export the transparent image with File → Export As... to a file format which supports transparency. That would be preferably PNG, but GIF would work as well.

The final result

4
  • 4
    You may want to grow selection by 1px to remove white edges (Select > Grow > 1 > OK) May 29, 2015 at 7:36
  • 4
    I am not at all versed with graphics design. Every rare occasion that i need to remove a background, i seem to be coming back to this answer. Thank you!
    – slayernoah
    Aug 16, 2016 at 18:05
  • 1
    I also found that using the Feather option in selection is also helpful for images with edges blurred against whitespace.
    – jocull
    Nov 28, 2017 at 16:33
  • 1
    Thanks: having a jpg with pure white background already, it was as simple as this: add transparency layer, select, delete.
    – djvg
    Jun 10, 2019 at 13:40
23

Sounds like you need to crop certain parts of the jpgs (the main figure, for example) and delete the "background". You can do so using the lasso tool.

The gimp website has lots of tutorials and explanations. Check this http://docs.gimp.org/en/gimp-painting.html#gimp-concepts-selection and this out: http://docs.gimp.org/en/gimp-tool-free-select.html

The polygonal selection creates an anchor point every time you click. Then moving the mouse pointer draws a line with a new anchor point that you can move as long as you don't click again.

You can access the Lasso Tool in different ways:

  • From the image menu bar Tools → Selection Tools → Free Select,

  • by clicking on the tool icon in the ToolBox,

  • by using the keyboard shortcut F.

To make the solid background of an image transparent, add an Alpha channel, and use the Magic Wand to select the background. Then, use the Color Picker tool to select the background color, which becomes the foreground color in Toolbox. Use the Bucket Fill tool with the selected color. Set the Bucket Fill mode to “Color Erase”, which erases pixels with the selected color; other pixels are partially erased and their color is changed.

0

A modern way of achieving this effect in your specific case is opening your image in the latest version of Gimp and from the top menu go to Colors -> Color to Alpha. Within that panel is Color is set to white, Gimp will attempt to replace all the white pixel areas with transparency. It's at least worth trying out.

Not the answer you're looking for? Browse other questions tagged or ask your own question.