Skip to content

identify -ping -format '%w %h' should output correct dimensions for PDF pages (instead of fixed 8.5x11.5 inch size) #373

@sladen

Description

@sladen

ImageMagick version

6.9.11-60

Operating system

Linux

Operating system, version and so on

Ubuntu 22.04.4 LTS

Description

Imagemagick provides identify -ping to perform quickly obtaining input image dimensions:

$ identify -ping -format '%w %h\n' pdfs/x.pdf 
612 828
612 828
$ identify pdfs/x.pdf
x.pdf[0] PDF 612x828 612x828+0+0 16-bit sRGB 2707B 0.000u 0:00.000
x.pdf[1] PDF 612x828 612x828+0+0 16-bit sRGB 2538B 0.000u 0:00.000

However, these dimensions are slightly scaled compared to the /MediaBox of the PDF:

$ identify -verbose pdfs/x.pdf | grep 'Page geometry:'
  Page geometry: 596x842+0+0
  Page geometry: 596x842+0+0
$ pdfinfo pdfs/x.pdf | grep 'Page.*s'
Pages:           2
Page size:       596 x 842 pts (A4)

Ideally identify would reliably return the actual image (PDF page /MediaBox) dimensions.


PS. One reference was found to trying pdf:HiResBoundingBox, but it's unclear if this is correct or should work:

$ identify -format '%[pdf:HiResBoundingBox]' pdfs/x.pdf
identify-im6.q16: unknown image property "%[pdf:HiResBoundingBox]" @ warning/property.c/InterpretImageProperties/4051.

Steps to Reproduce

$ identify -ping -format '%w %h\n' pdfs/x.pdf 
612 828

confirm this output differs, and appears to be slightly higher than:

$ pdfinfo pdfs/x.pdf | awk '/pts/{print $3,$5}'
596 842

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions