Page 1 of 1

Input page number => Output Filename

Posted: 2009-02-11T01:47:34-07:00
by ian_scho
Hi,

Due to the resource demands of converting a large PDF file to JPG (changing the volume for temporary files as well: set MAGICK_TMPDIR=y:\) I've split it into 100 pages at a time so for example:

Code: Select all

convert -limit memory 32mb -limit map 64mb -density 300 -thumbnail 93x131 example.pdf[0-99] thumbs\example.jpg
convert -limit memory 32mb -limit map 64mb -density 300 -thumbnail 93x131 example.pdf[100-199] thumbs100\example.jpg
As you can see, I will end up with 'n' thumbs directories each with 100 files called example-0.jpg to example-99.jpg.

I searched and found the following example which could dynamically write the width/height of an image to the file name:

Code: Select all

convert rose: -set filename:area "%wx%h" 'rose-%[filename:area].png'

After ferreting some more I have not yet found it possible to copy the input page number to an output name of the file. It would be similar to:
convert -limit memory 32mb -limit map 64mb -density 300 -thumbnail 93x131 example.pdf[100-199] -set filename:pg "%p" thumbs\example-%[filename:pg].jpg

I assume this functionality either doesn't exist, or spending the last 1.5 hours was insufficient to investigate the problem . :lol:

Cheers!

Re: Input page number => Output Filename

Posted: 2011-07-26T17:02:51-07:00
by vshih
This worked for me (version 6.6.9-4):

Code: Select all

convert ... -set filename:base %t rose-%[filename:base].jpg
This helped - http://imagemagick.org/script/escape.php

Re: Input page number => Output Filename

Posted: 2011-07-26T18:37:36-07:00
by anthony
Unless you are wanting to do mathematical calculations on the index, a simple count (with a starting point) can be achieved using a -scene options with a %d printf substitution....
http://www.imagemagick.org/Usage/files/#scene

However once you have assigned (-set) a number (or string) to an image that image will keep that same number, even if the images in memory are re-organised, parts deleted etc. That can be useful!

For example try this (quotes needed to protect the filename from the command line shell.

Code: Select all

   convert rose: -duplicate 4 -set filename:base %t \
         -reverse -set filename:index %t  +adjoin  "rose-%[filename:base]-%[filename:index].gif"
resulting filenames should be...
rose-4-0.gif rose-3-1.gif rose-2-2.gif rose-1-3.gif rose-0-4.gif

However it look like the current IM has a bug as it added a extra (unwanted) number to the resulting files.
Looks like a result of its normal multi-file write handling which should have been overridden.