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
Coding conversion
-
- Posts: 2
- Joined: 2011-09-10T09:46:47-07:00
- Authentication code: 8675308
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Coding conversion
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
convert desert.jpg -background white -gravity center -extent 2000x2000 desert.pdf
see
http://www.imagemagick.org/Usage/crop/#extent
-
- Posts: 2
- Joined: 2011-09-10T09:46:47-07:00
- Authentication code: 8675308
Re: Coding conversion
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Coding conversion
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
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
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Coding conversion
You will need to use a trick to use convert in this way...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
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/