multiple input and output files

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
jodel
Posts: 3
Joined: 2013-02-13T07:18:43-07:00
Authentication code: 6789

multiple input and output files

Post by jodel »

This is my first post so apologies if the question is basic.
I wish to take 4 or 5 files make a change to them and output the 4 or 5 again. I have it working doing it one by one but I would like to automate it with one command. The individual command is
convert -size 1024x768 xc:black -page +0+0 img001.jpg -layers flatten test001.jpg

I tried the following do do a series of files but it only does the first:
convert -size 1024x768 xc:black -page +0+0 'img*.jpg' -layers flatten test-%d.jpg
The output is only the first file as test-0.jpg not -1 -2 -3 etc as required
What syntax should I use?
Thanks
Jodel
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: multiple input and output files

Post by fmw42 »

Try using mogrify to composite the black image under the others. But I do not think it will work, because the output will be the same size as the images and not the background black. See

http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/basics ... fy_compose

But you should be able to use mogrify to either add a black border around the image or better just use -extent to your black size and -gravity to position it say in the middle

create a new directory where the output images will be placed
cd to directory with images
mogrify -path Path2/newfolder -format jpg -background black -gravity center -extent WxH image*.jpg
jodel
Posts: 3
Joined: 2013-02-13T07:18:43-07:00
Authentication code: 6789

Re: multiple input and output files

Post by jodel »

Thanks for your reply. The command I am using does exactly what I need, on a file by file basis so I would like to stick with it. What I am after is a means of getting that command structure to take say 4 input files and produce 4 output files. I suppose I could always try a bash script to loop through the command 4 times. Also, if I had a text file with each input file listed would that simplify matters?
Regards,
Jodel
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: multiple input and output files

Post by fmw42 »

convert will flatten all the images you specify into one image. That is why you need to either write a script or use mogrify

try

mogrify -path Path2/newfolder -format jpg -background black -gravity northwest -extent WxH image*.jpg

That will put your images into the top left corner of the black image of size WxH by extending the background to the size you want.

or try it with convert in the format you wanted

convert image*.jpg -background black -gravity northwest -extent WxH result_%d.jpg
jodel
Posts: 3
Joined: 2013-02-13T07:18:43-07:00
Authentication code: 6789

Re: multiple input and output files

Post by jodel »

Thanks. I will try as you suggest.
Jodel
Post Reply