How to Remove the Background of an Image in Krita

Share
In this tutorial, we'll learn how to remove the background of a photo or image in Krita (version 5.2). We can use this technique to make the background transparent, to change the background of the image to a plain color, pattern, or another image.

In general, to remove the background of an image in Krita, we'll follow the following steps:

1: open the image you want to edit in Krita.

2: using one of Krita's selection tools, we'll select the background area of the image that we want to remove. There are various ways to do this depending on the image, so we won't cover that in this tutorial.

3: after selecting the background area we want to remove, there are various ways to remove it.

Destructive method: click on Edit -> Clear on the menubar (keyboard shortcut: Delete key) to "delete" the selected pixels. This will make them transparent.

1st non-destructive method (eraser): click on the down arrow next to the plus ("+") button on the "Layers" docker, and select "Add Fill Layer." This will create a layer that has a solid color by default and set the selection as its internal transparency mask. After that, click on the dropdown list button on top of the "Layers" docker to change its blend mode from "Normal" to "Mix -> Erase." This will make every opaque pixel in the fill layer erase pixels under it.

2nd non-destructive method (transparency mask): instead of a fill layer, select "Add Transparency Mask" instead. This will create a transparency mask on the currently selected layer initializing it using the currently selected area. Since we have the background selected, this means that the background will be visible, and foreground will be invisible. To invert these two, make sure the transparency mask is selected, then click on Filters -> Adjust -> Invert on the menubar (keyboard shortcut: Ctrl+I). Internally, the "mask" of a transparency mask is a black and white layer, with "black" meaning "transparent." When we invert the colors, the black becomes white, and vice-versa, so what was transparent before becomes opaque, and vice-versa.

If you have followed the steps successfully, you should be seeing a checkboard pattern behind the image where you deleted the pixels. This checkboard effect is used to identify transparent areas in image editors. There are two ways to proceed:

  1. Save the image with transparency.
  2. Set a background color on the image, such as white, and then save it.

Let's do the first way first, since it's simpler.

Exporting the Image with Transparency

In order to export the image with transparency, we need to use a format that supports transparency, such as PNG or WebP. If you aren't sure which to choose, PNG is the safest choice.

Click on File -> Export on the menubar, navigate to the folder where you want to save the image, and type a filename that has the file extension .png, such as photo.png. Then click on the "Save" button.

Krita will show a dialog box with options to configure the PNG codec. The important option for us is "Store alpha channel (transparency)." This must be checked so that it the exported PNG has transparency. After you click "OK" the file will be exported with transparency.

Note: if you're using your transparent images in some program that uses transparent pixels for something, and you noticed your transparent pixels have become black, that's because this method will compose the layers using pre-multiplied alpha, so fully transparent pixels are always going to be black. If you need colored transparent pixels, you need a transparency mask on the layer; then you right click on the transparency mask, and in its context menu, you click on "Split Alpha -> Save Merged...."

Changing the Background of the Image

If you've followed the section above, you may have noticed that you have the option to export PNG without transparency, in which case you will be able to select a color for the transparent pixels in the PNG export dialog.

Alternatively, you can also add a different background to the image as a separate layer.

If you want a solid color or a simple pattern, add a fill layer in the "Layers" docker. By default, it will be added on top of the current layer, so everything will become a single flat color. You have to drag it under the other layer.

You may drag a different image file into Krita, and import it as a layer so you can place it under the semi-transparent photo the exact same way.

Afterwards, when exporting the image, we'll probably want to use JPG instead of PNG, because the file is going to be smaller, but the process is the same.

Saving your Work

If you want to save your work so that you can edit it later in Krita, you need to save a .kra file as well.

Comments

Leave a Reply

Leave your thoughts! Required fields are marked *