Converting images to PDF with same resolution

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
MavFurious

Converting images to PDF with same resolution

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Converting images to PDF with same resolution

Post 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 ?
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Converting images to PDF with same resolution

Post 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.
Post Reply