Convert multi image PDF in single files with image size in title

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

Convert multi image PDF in single files with image size in title

Post by LittleKI » 2018-02-01T06:47:37-07:00

Hi,

i use this command line to convert multi image pdfs into single files:

Code: Select all

convert -density 300x300 -units pixelsperinch input -background white -alpha background -alpha off -antialias -compress zip +adjoin output.tiff
then i tried to add some information into the output filename as i could read here: viewtopic.php?t=17149. i tried this command line:

Code: Select all

convert -density 300x300 -units pixelsperinch input -background white -alpha background -alpha offantialias -compress zip -set filename:mysize '%wx%h' +adjoin output_%[filename:mysize].tif
convert only writes the first side as a image. the output filename is correct: new_2250x4000.tif

what is wrong with the second command? why only the first image is written to a image?

snibgo
Posts: 10144
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert multi image PDF in single files with image size in title

Post by snibgo » 2018-02-01T10:27:34-07:00

I suspect they are all being written, but they have the same size, so they have the same name. Your filename overrides the default numbering mechanism.
snibgo's IM pages: im.snibgo.com

LittleKI
Posts: 32
Joined: 2015-01-11T11:55:29-07:00
Authentication code: 6789

Re: Convert multi image PDF in single files with image size in title

Post by LittleKI » 2018-02-01T11:26:04-07:00

yes, its right.

but normally when i use normal output convert creates numbers after the filename, like output1.tif output2.tif. this doesn't work when i use the output with image size in the file name. when i try this

Code: Select all

convert -density 300x300 -units pixelsperinch input.pdf -background white -alpha background -alpha off -antialias -compress zip -set filename:mysize '%wx%h' +adjoin new_%[filename:mysize]_%02d.tif
i have 1 output file and the name is 'new_2250x4000_%02d.tif.tif'. when i try this

Code: Select all

convert -density 300x300 -units pixelsperinch input.pdf -background white -alpha background -alpha off -antialias -compress zip -set filename:mysize '%wx%h' +adjoin new_%02d_%[filename:mysize].tif
i have one image for every side and the output name are new_00_%[2250x4000.tif and new_01_%[2250x4000.tif.

what is the right way to output the images with the image size in the name AND with correct numbering?

snibgo
Posts: 10144
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert multi image PDF in single files with image size in title

Post by snibgo » 2018-02-01T11:45:02-07:00

I would use %s in the "-set filename", so you can have it wherever you want, eg:

Code: Select all

-set filename:mysize '%wx%h_%s'
-set filename:mysize '%s_%wx%h'
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 23055
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert multi image PDF in single files with image size in title

Post by fmw42 » 2018-02-01T11:55:21-07:00

Please always provide your IM version and platform/OS when asking questions.

I do not believe you can use more than one % in your output file name. But you can get the scene number from %s. So this works.

Code: Select all

convert -density 150 test.pdf -set filename:mysize '%s_%wx%h' -compress zip +adjoin new_%[filename:mysize].tif
Produces:

Code: Select all

new_0_533x533.tif
new_1_552x694.tif
new_2_833x623.tif
I think it would need a new -define to be created to tell IM that scene numbers should have leading zeros or a new string format.

Also I note that when I add -scene 1 to the command line, it did not shift the numbers to start with 1.

LittleKI
Posts: 32
Joined: 2015-01-11T11:55:29-07:00
Authentication code: 6789

Re: Convert multi image PDF in single files with image size in title

Post by LittleKI » 2018-02-02T08:56:02-07:00

i use version 6.8.9.9 on ubuntu 16.04.
I think it would need a new -define to be created to tell IM that scene numbers should have leading zeros or a new string format.
what do you mean? i read the command line options but didn't understand ow i can do this with -define.

User avatar
fmw42
Posts: 23055
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert multi image PDF in single files with image size in title

Post by fmw42 » 2018-02-02T10:10:51-07:00

The define does not exist, yet. I was suggesting that a new one would be needed to do what you want, i.e. an enhancement to imagemagick.

LittleKI
Posts: 32
Joined: 2015-01-11T11:55:29-07:00
Authentication code: 6789

Re: Convert multi image PDF in single files with image size in title

Post by LittleKI » 2018-02-02T12:05:04-07:00

but how can i create a new one? i dont understand whats written in "command line option".

User avatar
fmw42
Posts: 23055
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert multi image PDF in single files with image size in title

Post by fmw42 » 2018-02-02T12:14:23-07:00

You cannot, unless you can code for ImageMagick. You need to request and enhancement for such. See my the bottom of my bug report at viewtopic.php?f=3&t=33455. You can make a formal request for such an enhancement on the Developers forum.

Post Reply