Discussion:
convert gif/png/... to pdf
Antje Schweitzer
2011-07-14 15:09:03 UTC
Permalink
Dear list,

is there a way to automatize converting pictures to pdf files in which
there is no additional white space around the picture?

I've been doing this manually for a while using the display interface
and manually setting the pdf page size to the dimensions of the picture
when saving, but this is tedious.
I've tried to do it automatically from the shell using a script like this

#!/bin/tcsh
convert $1 -resize `identify -format "%wx%h" $1` $2

however, specifying the desired width and height for the output pdf file
this way yields different results than when setting the same width and
height using display. The final result has a smaller size, see below:

prompt> identify -format "%wx%h" vowels.png
959x842
prompt> convert vowels.png -size 959x842 vowels.pdf
prompt> identify -format "%wx%h" vowels.pdf
1600-1200

How do I have to set the size to end up with a pdf file that has the
intended dimensions?

Any help would be greatly appreciated!

Antje Schweitzer
--
Antje Schweitzer
IMS Uni Stuttgart
0711-685 81376
http://www.ims.uni-stuttgart.de/~schweitz
Antje Schweitzer
2011-07-14 15:10:20 UTC
Permalink
Post by Antje Schweitzer
prompt> identify -format "%wx%h" vowels.png
959x842
prompt> convert vowels.png -size 959x842 vowels.pdf
prompt> identify -format "%wx%h" vowels.pdf
1600-1200
... this should have been 1600x1200 (had had a typo in the format
command, - instead of x)
Fred Weinhaus
2011-07-14 16:31:33 UTC
Permalink
PNG supports a virtual canvas. That may be the cause of the extra
space. It can be removed by adding +repage after reading your input
image.

You can check for it from identify -verbose image or from string formats:

%P, (%W and %H), %X, %Y



see http://www.imagemagick.org/script/escape.php
Post by Antje Schweitzer
Post by Antje Schweitzer
prompt> identify -format "%wx%h" vowels.png
959x842
prompt> convert vowels.png -size 959x842 vowels.pdf
prompt> identify -format "%wx%h" vowels.pdf
1600-1200
... this should have been 1600x1200 (had had a typo in the format
command, - instead of x)
Fred Weinhaus
2011-07-14 19:36:53 UTC
Permalink
-size has no effect here. -resize would be better, but the size of
the pdf is controlled by -density as it is a vector format.

logo: image is 640x480

using -density 72 will produce the same size pdf
using -density 144 will produce half that size pdf

convert logo: -density 72 logo1.pdf
convert logo: -density 144 logo2.pdf
identify logo1.pdf logo2.pdf
logo1.pdf PDF 640x480 640x480+0+0 16-bit Bilevel DirectClass 38.5KB
0.020u 0:00.000
logo2.pdf[1] PDF 320x240 320x240+0+0 16-bit Bilevel DirectClass
9.66KB 0.000u 0:00.000
Post by Antje Schweitzer
convert vowels.png -size 959x842 vowels.pdf
Loading...