Batch composite hundreds 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
robocop
Posts: 32
Joined: 2013-03-22T23:15:09-07:00
Authentication code: 6789

Batch composite hundreds of images

Post by robocop »

Hi folks!

I've searched the forums and tried several methods but i am unable to get what i need to work.

Basically i have several hundred images which i would like composited onto a single common background.

Common background image:
Image

Sample Image:
Image

Result:
Image

I am currently using the following code:

Code: Select all

composite -gravity center -geometry -0+5  top1.jpg  back.jpg  composite_top1.jpg
Is there a way to accomplish this in batch?

Thank you so much for your help!
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 | Ubuntu 18.04.1 LTS
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch composite hundreds of images

Post by snibgo »

You could put it in a for loop, for example:

Code: Select all

md newdir

for VAR in $(ls *.jpg)
do
  echo $VAR

  composite -gravity center -geometry -0+5 $VAR back.jpg newdir\$VAR
done
snibgo's IM pages: im.snibgo.com
robocop
Posts: 32
Joined: 2013-03-22T23:15:09-07:00
Authentication code: 6789

Re: Batch composite hundreds of images

Post by robocop »

snibgo wrote: 2018-06-11T03:14:06-07:00 You could put it in a for loop, for example:

Code: Select all

md newdir

for VAR in $(ls *.jpg)
do
  echo $VAR

  composite -gravity center -geometry -0+5 $VAR back.jpg newdir\$VAR
done
Hi snibgo,

Thank you very much! I tried what you mentioned. I put your code in a .sh file ( composite.sh ) and ran "sh composite.sh" from Ubuntu terminal.

Nothing happened expect the red back.jpg file was duplicated to a new file called "newdir$VAR"

Am i doing something wrong ?

Thank you
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 | Ubuntu 18.04.1 LTS
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch composite hundreds of images

Post by snibgo »

Yeah, my fault, sorry. For bash, use forward slash "/" as directory separator. And use "mkdir" to create a directory:

Code: Select all

mkdir newdir

for VAR in $(ls z*.jpg)
do
  echo $VAR

  composite -gravity center -geometry -0+5 $VAR back.jpg newdir/$VAR
done
snibgo's IM pages: im.snibgo.com
robocop
Posts: 32
Joined: 2013-03-22T23:15:09-07:00
Authentication code: 6789

Re: Batch composite hundreds of images

Post by robocop »

snibgo wrote: 2018-06-11T03:46:33-07:00 Yeah, my fault, sorry. For bash, use forward slash "/" as directory separator. And use "mkdir" to create a directory:

Code: Select all

mkdir newdir

for VAR in $(ls z*.jpg)
do
  echo $VAR

  composite -gravity center -geometry -0+5 $VAR back.jpg newdir/$VAR
done
Hi snibgo : )

Wow Thank you so much!

It worked perfectly! Just what i needed.

Your help is much appreciated.

Thank you again for helping me! : )))
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 | Ubuntu 18.04.1 LTS
Post Reply