Page 1 of 1

Converting images to PDF with same resolution

Posted: 2010-06-22T02:53:26-07:00
by MavFurious
Hi all,

i have a simple problem, i think, but i don't find a solution.

I have one jpeg file:

Code: Select all

identify -verbose Image-002.jpg | head
Image: Image-002.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Class: DirectClass
  Geometry: 1226x905+0+0
  Resolution: 150x150
  Print size: 8.17333x6.03333
  Units: PixelsPerInch
  Type: TrueColor
  Endianess: Undefined
  Colorspace: RGB
If i use

convert Image-002.jpg Image-002.pdf

the resulting file is

Code: Select all

identify -verbose Image-002.pdf | head
Image: Image-002.pdf
  Format: PDF (Portable Document Format)
  Class: DirectClass
  Geometry: 588x434+0+0
  Resolution: 72x72
  Print size: 8.16667x6.02778
  Units: Undefined
  Type: TrueColor
  Endianess: Undefined
  Colorspace: RGB
How can i obtain the same parameters of the original file automatically?

Thanks a lot

Alberto

Re: Converting images to PDF with same resolution

Posted: 2010-06-22T04:26:34-07:00
by Bonzo
I would say you need to get the resolution into a variable and use that in the code. How are you running your code ?

Re: Converting images to PDF with same resolution

Posted: 2010-06-22T08:51:37-07:00
by Drarakel
PDF is different from 'normal' image files. The geometry value here shows the width and height at 72dpi (default density for PDF) - not the direct values of your original JPG image. This wouldn't be possible for all PDFs as it can contain several overlayed images, vector-graphics etc.
When handling PDFs, you have to specify a density that you want to read in (when you don't specify one, ImageMagick uses the 72dpi). Your original file had 150dpi, so read it with 150dpi:
identify -verbose -density 150 Image-002.pdf
convert -density 150 Image-002.pdf output.png

Other possiblity: You could trick ImageMagick by changing the density value before creating the PDF:
convert -units PixelsPerInch Image-002.jpg -density 72 Image-002.pdf
Then the PDF will show about 1226x905 even at 72dpi.
But the latter is not the recommended way.