We ❤️ Open Source
A community education resource
How to create a holiday card with open source tools
Easily remove photo backgrounds this holiday season using rembg.
This year, there are several open source tools available that can help you create a personalized holiday card. If you have a great photo of your family or grandchildren but want to change the background—perhaps to fit a festive winter scene—you can use a Python module called rembg
to remove and replace the background. Here’s how you can get started with it.
Getting started
First, set up a Python virtual environment to keep things organized. I created a directory named rembg
with the following command:
$ mkdir rembg
Next, set up the virtual environment:
python3 -m venv /home/don/rembg
Then activate the environment with this command:
source /home/don/rembg/bin/activate
Now, you’re ready to install the necessary dependencies. First, install rembg
:
pip3 install rembg
To use rembg
from the command line, install the command-line interface as well:
pip3 install "rembg[cli]"
You’ll also need onnxruntime
, which acts as a machine learning accelerator:
pip3 install onnxruntime
Removing the background
Now, let’s get to the fun part—removing the background from your image. I’ve selected a recent photo of my wife and I, taken in the fall. While I love the image, I’d like to give it a more festive backdrop.
Make sure your image is in the rembg
folder, and then run this command to remove the background:
rembg i grandparents.jpg grandparents_no_bg.jpg
In this command, the i
flag tells rembg
to process the file. I also renamed the output file (grandparents_no_bg.jpg
) to keep the original image in case I want to use it again. After running the command, you should see that the background has been removed from your image.
Adding a new background
Once the background is removed, you can get creative. For my card, I used InkScape to design a festive background. I added some holiday lettering and a Poinsettia image I downloaded from OpenClipart.org. The completed card turned out beautifully!
Both rembg
and onnxruntime
are open source with an MIT License.
More from We Love Open Source
- Free tools to create cards, videos, and more
- Getting started with Llamafile tutorial
- Saving vintage recordings with Linux
- Getting started with Upscayl tutorial
- Getting started with PhotoCollage tutorial
This article is adapted from “Transforming family photos into festive holiday cards with AI” by Don Watkins, and is republished with permission from the author.
The opinions expressed on this website are those of each author, not of the author's employer or All Things Open/We Love Open Source.