Page 1 of 1

Batch composite hundreds of images

Posted: 2018-06-11T02:23:13-07:00
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!

Re: Batch composite hundreds of images

Posted: 2018-06-11T03:14:06-07:00
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

Re: Batch composite hundreds of images

Posted: 2018-06-11T03:37:27-07:00
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

Re: Batch composite hundreds of images

Posted: 2018-06-11T03:46:33-07:00
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

Re: Batch composite hundreds of images

Posted: 2018-06-11T03:54:09-07:00
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! : )))