Odd string formatting results for output file names...
Posted: 2017-02-21T10:49:04-07:00
Using IM 7.0.5-0 on Windows 10 64.
I start by making an animated GIF just to use as an example of a multi-layer image with this command...
Then I convert that "animrose.gif" into PNG files from the separate layers like this...
This creates the six images I'd expect, but the file names have done something funny...
The files get numbered and padded to two places with leading zeroes, but the string formatting code "%02d" is still in there as part of the file name.
If I run the same command but put that underscore in the output file name at the end instead of in the "-set filename:f" like this...
I get an even stranger result...
The filenames obtain an extra dot "." before the sequence numbers.
These discrepancies seem to behave differently when using different input and/or output file formats, too. If I start with this multi-layer TIF...
... and run essentially the same command as above that inserted the extra dots "." in the filenames, those dots don't appear...
And if I make the rose into a multipage PDF...
... and run it through this command...
... it actually inserts an extra "j" and the extra dot "." in each filename. So that's weird.
Now it could be using this sort of string formatting for output file names is undefined behavior when mixing it with "%[filename:f]", and maybe I shouldn't expect it to work at all. But if any of the combinations above are supposed to produce sequentially numbered output file names according to the string formatting "%02d", something isn't quite right. Any ideas?
I start by making an animated GIF just to use as an example of a multi-layer image with this command...
Code: Select all
magick rose: -duplicate 5 -virtual-pixel tile ^
-distort affine "0,0 0,%[fx:t*h/n]" -set delay 50 -loop 0 animrose.gif
Code: Select all
magick animrose.gif -set filename:f "%[t]_" %[filename:f]%02d.png"
Code: Select all
animrose_%02d00.png
animrose_%02d01.png
animrose_%02d02.png
animrose_%02d03.png
animrose_%02d04.png
animrose_%02d05.png
If I run the same command but put that underscore in the output file name at the end instead of in the "-set filename:f" like this...
Code: Select all
magick animrose.gif -set filename:f "%[t]" %[filename:f]_%02d.png"
Code: Select all
animrose_%02d.00.png
animrose_%02d.01.png
animrose_%02d.02.png
animrose_%02d.03.png
animrose_%02d.04.png
animrose_%02d.05.png
These discrepancies seem to behave differently when using different input and/or output file formats, too. If I start with this multi-layer TIF...
Code: Select all
magick rose: -duplicate 5 -virtual-pixel tile -distort affine "0,0 0,%[fx:t*h/n]" multirose.tif
Code: Select all
multirose_%02d00.png
multirose_%02d01.png
multirose_%02d02.png
multirose_%02d03.png
multirose_%02d04.png
multirose_%02d05.png
Code: Select all
magick rose: -duplicate 5 -virtual-pixel tile -distort affine "0,0 0,%[fx:t*h/n]" pdfrose.pdf
Code: Select all
magick pdfrose.pdf -set filename:f "%[t]" %[filename:f]_%02d.jpg"
Code: Select all
pdfrose_%02d.j00.jpg
pdfrose_%02d.j01.jpg
pdfrose_%02d.j02.jpg
pdfrose_%02d.j03.jpg
pdfrose_%02d.j04.jpg
pdfrose_%02d.j05.jpg