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 » 2018-03-03T15:28:37-07:00

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: 23245
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 » 2018-03-03T15:32:24-07:00

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 » 2018-03-04T01:24:18-07:00

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: 23245
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 » 2018-03-04T13:32:14-07:00

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: 23245
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 » 2018-03-05T17:58:53-07:00

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 » 2018-03-05T22:48:49-07:00

What is the different? you use %w and %h instead of %W. but i cant see any other different.

User avatar
fmw42
Posts: 23245
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 » 2018-03-06T10:40:53-07:00

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