Leading Zero and Resolution in Output file name

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
LittleKI
Posts: 32
Joined: 2015-01-11T11:55:29-07:00
Authentication code: 6789

Leading Zero and Resolution in Output file name

Post by LittleKI »

Hi,

i use this script to convert pdf files into several images files:

Code: Select all

convert -density 300x300 -units pixelsperinch input.pdf -background white -alpha background -alpha off -resize 25% -compress jpeg +adjoin -set filename:mysize '%s_%G' "output_%[filename:mysize].tif"
IM writes the width and the height of in INPUT in the output file name, but what i need is the width and hight of the output files. how can i do this?

IM also writes the page numbers to the output file name, starting with 0 and without leading zeros. is there any way to add leading zeros depending on the the number of pages of the input file? if the pdf has more then 10 but less then 100 pages with 0 leading zero and more then 100 pages with two leading zeros?

without the width/height in the file name i would do this with "-%02d" but i seems this doesn't work together. when i try this

Code: Select all

+adjoin -set filename:mysize '%G' "output_-%02d_%[filename:mysize].tif"
the output file name is

Code: Select all

output_-00_%[4944x6942.tif
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Leading Zero and Resolution in Output file name

Post by fmw42 »

There is a known bug that is being worked on for the next release. See viewtopic.php?f=3&t=33455
LittleKI
Posts: 32
Joined: 2015-01-11T11:55:29-07:00
Authentication code: 6789

Re: Leading Zero and Resolution in Output file name

Post by LittleKI »

OK, this will fix the problem with the wrong output names.

But there is still the problem with the missing leading zeros when original pdf has more then 10 or 100 pages. is there a solution?

the same with the wrong resolution in the output name? or can i calculate this directly in the command? something like

-set filename:mysize '%G/2'

when i use -resize 50%?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Leading Zero and Resolution in Output file name

Post by fmw42 »

I believe you would need to do then one at a time such as

-set filename:mywidth "%[fx:w/2]" and -set filename:myheight "%[fx:h/2]

then use both in your output. However %G refers to the original size and w,h refer to the current size. I am not sure there currently is an equivalent for each original dimension separately in the string formats. I may be wrong.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Leading Zero and Resolution in Output file name

Post by fmw42 »

If you want the size of the output in the filenames, then do the following with the latest version of ImageMagick (7.0.7.25 and 6.9.9.37)

Code: Select all

convert -density 300x300 -units pixelsperinch test.pdf -background white -alpha background -alpha off -resize 25% -compress jpeg +adjoin -set filename:mysize '%wx%h' "output_%02d_%[filename:mysize].tif"
This gives me:

output_00_267x267.tif
output_01_276x347.tif
output_02_417x312.tif

If you want to start at one then add -scene 1 after convert.
LittleKI
Posts: 32
Joined: 2015-01-11T11:55:29-07:00
Authentication code: 6789

Re: Leading Zero and Resolution in Output file name

Post by LittleKI »

What is the different? you use %w and %h instead of %W. but i cant see any other different.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Leading Zero and Resolution in Output file name

Post by fmw42 »

You reported:

output_-00_%[4944x6942.tif

Mine has the [ removed.

You also used %G not %W. Also you were trying to do division by 2 and as I said above, that is not possible unless you use single arguments and %[fx:...]

As I mentioned above, there was a bug that has now been fixed.

Perhaps I misunderstand your question. Please repeat what you think is wrong, now.
Post Reply