Simplest to add a background image to a batch of images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
higps
Posts: 1
Joined: 2019-09-04T06:10:58-07:00
Authentication code: 1152

Simplest to add a background image to a batch of images

Post by higps » 2019-09-04T06:15:56-07:00

I have a batch of roughly 2000 png image files with alpha layer.

I want to add a background image to those 2000 files.

I'm a newbie at this so I'm not sure what type of method I should use to combine this.

I have the background file in a separate folder from the batch.

All that needs to be done is to combine the background image with each of the batch files, so other modification is needed.

Is there a simple way to just combine all images in folder x with image y.png?

I've looked around in the documentation and this forum, and I'm not really sure what's best for my case.

snibgo
Posts: 12157
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Simplest to add a background image to a batch of images

Post by snibgo » 2019-09-04T07:10:55-07:00

What version of IM, on what platform?

The first step is to find the IM command that does what you want to a single input image. Perhaps:

Code: Select all

magick in.png backgnd.png -composite out.png
When you know what command you need, the simplest way to apply that to all the images is to put that command in a shell loop. However, if the inputs are small you might do it in a single IM command, and this may be faster because the background image needs to be read just once.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Simplest to add a background image to a batch of images

Post by fmw42 » 2019-09-04T09:23:22-07:00

You can use mogrify to process all images in a directory with one common image in a composite operation. See

https://imagemagick.org/Usage/basics/#mogrify
https://imagemagick.org/Usage/basics/#mogrify_compose

First create a new directory to hold all your images.

Code: Select all

mogrify -path path/to/newdirectory -format png -draw 'image Dst_Over 0,0 0,0 "background.png"' *.png
If using IM 7, the add magick before mogrify.

Post Reply