Page 1 of 1
Coding conversion
Posted: 2011-09-10T10:13:21-07:00
by wuschelweich
Dear Magick users,
Im facing problems with converting graphic-files (e.g.: .png, .gif, .jpg etc.) to .pdf format through the command line. I'd like to not only convert the graphic to .pdf format but also resize it and place it in the middle of the .pdf. I attached two sample files which should explain what I am trying to accomplish. Could perhaps someone help me with the coding?
Original:
http://mundmpersonalmarketing.webatu.com/Desert.jpg
How it is supposed to look after the conversion:
http://mundmpersonalmarketing.webatu.com/sample.pdf
I am using: ImageMagick-6.7.2-Q16
Thank you very much in advance,
Andreas
Re: Coding conversion
Posted: 2011-09-10T11:58:48-07:00
by fmw42
try this. pad the image with white to the size you want with the image in the center, then convert to pdf
convert desert.jpg -background white -gravity center -extent 2000x2000 desert.pdf
see
http://www.imagemagick.org/Usage/crop/#extent
Re: Coding conversion
Posted: 2011-09-10T15:02:19-07:00
by wuschelweich
Dear fmw42,
that's what I was looking for. I've modified your code a little to convert a whole folder of .png graphic files to .pdf format AND keep the old filename:
convert *.png -background white -gravity center -extend 762x1072 *.pdf
Unfortunately it isnt working. Do you perhaps have an idea?
Thanks a lot,
Andreas
Re: Coding conversion
Posted: 2011-09-10T17:17:27-07:00
by fmw42
convert can only have one output image. You cannot use wildcards for output. You can make a script to loop over your images or use mogrify as that can have one output for every image in a folder and write them to a new folder.
see mogrify at
http://www.imagemagick.org/Usage/basics/#mogrify
mogrify -path path2newfolder -format pdf -background white -gravity center -extent 2000x2000 *.jpg
You have to make the output size larger than your input in order to have some white padding around the image. It does no good to have -extent the same size as your input image. However, you can choose some other size than 2000x2000 as appropriate to the largest image you have to process. If you want the padding to be the same amount for all sizes of images, then replace -background white -extent
(note it is extent and not extend) with -bordercolor white -border 100 or whatever border size you want. See
http://www.imagemagick.org/Usage/crop/#border
Re: Coding conversion
Posted: 2011-09-14T18:59:12-07:00
by anthony
wuschelweich wrote:Dear fmw42,
that's what I was looking for. I've modified your code a little to convert a whole folder of .png graphic files to .pdf format AND keep the old filename:
convert *.png -background white -gravity center -extend 762x1072 *.pdf
Unfortunately it isnt working. Do you perhaps have an idea?
Thanks a lot,
Andreas
You will need to use a trick to use convert in this way...
Using Convert Instead of Morgify
http://www.imagemagick.org/Usage/basics ... fy_convert
However Fred is correct mogrify is better for simple loops over images, otherwise a shell wrapper can be used to loop over the images.