Input page number => Output Filename

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
ian_scho

Input page number => Output Filename

Post 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!
vshih
Posts: 1
Joined: 2011-07-26T16:46:49-07:00
Authentication code: 8675308

Re: Input page number => Output Filename

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Input page number => Output Filename

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply