How can I remove the background and replace with transparency (as represented by checkered background in PS)? And are there any limitations in the file type I can then export the image to?
- Open the image and choose Select > By Color from the menu.
- Click on the color you'd like to remove.
- Select Colors > Color to Alpha from the menu and click OK.
This will result in the transparent, checkered background that you're looking for. If the background is made up of multiple colors, just repeat these three steps as necessary.
Beware of simplistic solutions
On CGI (logos, text), the smooth edges are produced with anti-aliasing pixels. These pixels have a color which is a mix of the background color and the subject color. When you use the color selector or the fuzzy selector, these pixels are either selected fully (if they are close enough) or not at all, depending on threshold. If you then bluntly Delete, you either get a halo with the color of the removed background (Threshold 15) or a jagged edge (Threshold 100) or both:
A good solution
The good solution is to replace the background color by transparency, in proportion of its contribution to the color mix. In Gimp there are two ways to achieve this:
Colors>Color to alpha
Color erasemode, as a paint tool mode, or since Gimp 2.10 as a layer blend mode.
They both replace the pixel by the most transparent pixel, which, put over the removed color, re-produces the initial color. If you remove red from purple, you get a semi transparent blue, because semi-transparent blue over red produces purple. If you remove white from gray, you get a very transparent black pixel and not a not-so-transparent dark gray pixel, because among several solution Gimp picks the most transparent one.
For instance, using Color-to-alpha to remove the red gives this:
You will notice that in the 2.8 results, there are darker pixels that are due to Gimp 2.8 working on gamma-corrected values (the result is still vastly better than the jagged edges you get with simpler methods). Gimp 2.10 works in "linear light" and has no such problems.
In the general case, the subject may have parts that are close to the color of the background. So if you apply the technique above these parts become transparent (or partially transparent). Avoiding this is simple:
- Use the wand to select the background. The usual threshold (15) is fine.
Select>Growthe selection so that it covers the anti-aliasing pixels. On a clean image (PNG, with no JPG history) you don't need to grow by more than one pixel. If the image is dirty (JPEG artifacts), growing the selection by two or three pixels can be necessary.
- Apply color-to-alpha. The pixels inside the subject, bieng excluded from the selection, won't be altered. Color to alpha will be applied to the background and the edge pixels, where it matters.
Output file types
- JPEG doesn't support transparency
- GIF supports binary transparency (all opaque or all transparent) so your semi-transparent edge pixels are going to be altered. You can use `Layer>Transparency>Semi-flatten to fill the transparency of these edge pixels with a new color (the color of the background on which the GIF will be used).
- PNG has full support for partial transparency and is currently the preferred format.
- WEBP is a new Google-sponsored format that can be lossy or lossless, and supports partial transparency. Gimp 2.10 supports it, but you have to ensure that it is supported where you want to use it (it won't be supported in older browsers, for instance).
convert file.gif -transparent white -fuzz 10% file-2.gif`.
You could use
"#ededee" to specify the color in hexadecimal.
Probably more complicated but there is an option to work with multiple layers/frames at once with this solution.