Page 1 of 1

Simplest to add a background image to a batch of images

Posted: 2019-09-04T06:15:56-07:00
by higps
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.

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

Posted: 2019-09-04T07:10:55-07:00
by snibgo
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.

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

Posted: 2019-09-04T09:23:22-07:00
by fmw42
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.