Transforming Family Photos into Festive Holiday Cards with AI

There are several open-source tools available this year for creating holiday cards. If you have a wonderful photo of your family or grandchildren, but it was taken during a different season and you’d like to change the background, there’s a Python module called rembg that can help you with that. To get started, you’ll need to set up a Python virtual environment and install the necessary dependencies. I created a directory named rembg using the following command:

$ mkdir rembg 

Then I setup a Python virtual environment.

python3 -m venv /home/don/rembg

Then I activate the environment with the following command.

source /home/don/rembg/bin/activate

Then I install rembg:

pip3 install rembg

I want to use rembg from the command line so I make the following additional installation:

pip3 install "rembg[cli]"

Then I install onnxruntime which is a machine learning accelerator.

pip3 install onnxruntime

Now I am ready to remove the background from the image that I have chosen. This is a recent picture of my wife and I taken in the fall of the year. I like the picture but I want it to have a festive background.

Photo by https://www.sissyhorch.com/

I make sure that my image is in the rembg folder and then execute the following command. The i switch means that I am operating at the file level.

rembg i grandparents.jpg grandparents_no_bg.jpg

In the command above I renamed the output file so that I would still have my original just in case I wanted to use it again. You can see below that the background has been removed from the image above.

I can create a nice background for my card with InkScape and add some festive lettering and use a Pointsettia I downloaded from Openclipart.org. The completed card is shown below.

Created with InkScape, OpenClipart.org by Don Watkins CC by SA 4.0

Rembg is open source with an MIT License. Onnxruntime is open source with an MIT License.

Leave a Reply

Your email address will not be published. Required fields are marked *