Page 1 of 1
Output file globbing
Posted: 2017-09-03T11:08:29-07:00
by jwes
I have a program that outputs a number of files, e.g. in1,in2,...in499,in500. I want to use IM to do the same thing to each of these files.
in1 --> out1
in2 --> out2
...
in500 -->out500
On windows 7, using IM 7.0.6, if I do magick in*.png -dosomething out%d.png, they come out in some odd order. I can do magick in%d.png[1-500] -dosomething out%d.png, which gives in1 --> out0, ..., as long as the input files are all in sequence. What I would like to do is magick in*.png -dosomething out%s.png, which could replace the '%s' with whatever is matched by the '*'. Any suggestions?
Re: Output file globbing
Posted: 2017-09-03T12:06:07-07:00
by GeeMack
jwes wrote: ↑2017-09-03T11:08:29-07:00On windows 7, using IM 7.0.6, if I do magick in*.png -dosomething out%d.png, they come out in some odd order. I can do magick in%d.png[1-500] -dosomething out%d.png, which gives in1 --> out0, ..., as long as the input files are all in sequence. What I would like to do is magick in*.png -dosomething out%s.png, which could replace the '%s' with whatever is matched by the '*'. Any suggestions?
There are a couple ways to approach this. The simplest method for specifying the order of the named output files is to modify your string formatting of the output file name something like this...
Code: Select all
magick input*.png -resize 50% output%03d.png
Using "%03d" there will force IM to pad the numbers with zeros to three places. The output will be "output000.png", "output001.png" "output002.png", etc. You can tell it to pad with as many zeros as needed to accommodate the expected number of output files with "%02d" for two places, or "%09d" for nine places, or whatever. Also, if you want the output files to start with a number other than zero, use "-scene N" before the output where "N" is the starting number for your sequence.
Another angle would be to use the input file names to create the output file names. You can do something like this...
Code: Select all
magick input*.png -set filename: "out_%[t]" -resize 50% "%[filename:].png"
That will substitute the "%[t]" for the input file name without the extension, and add the "out_" as a prefix. Your output files will be named something like "out_inputname1.png", "out_inputname2.png", "out_inputname3.png", etc.
Find out more about using IM's formatting escapes
at THIS link.
In a BAT script you'll have to make all those single percent signs "%" into doubles "%%".
Re: Output file globbing
Posted: 2017-09-03T13:32:14-07:00
by snibgo
Another possibility is to have one convert per input file, in a shell script loop that processes all in*.png files, and creates an output name something like:
Then if an infile is named in543.png, the outfile would be named out543.png.