ImageMagick6 icon indicating copy to clipboard operation
ImageMagick6 copied to clipboard

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

Open sladen opened this issue 7 months ago • 3 comments

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

sladen avatar Jun 11 '25 10:06 sladen

Post a link to x.pdf so we can download and reproduce the issue. Thanks.

urban-warrior avatar Jun 15 '25 13:06 urban-warrior

Different PDF, a minimal working example PDF, but happens with all PDFs tested:

$ wget -nv http://www.paul.sladen.org/projects/pdfutils/minimal.pdf
2025-06-16 06:06:06 http://www.paul.sladen.org/projects/pdfutils/minimal.pdf [2439/2439] -> "minimal.pdf"
$ pdfinfo minimal.pdf | awk '/pts/{print $3,$5}'
595 842
$ identify -ping -format '%w %h\n' minimal.pdf 
612 828
$ for i in 8.5 11.5 ; do units "$i inch" pspoint ; done | xargs echo | awk '{print $2,$6}'
612 828

Thus, it would seem that identify -ping perhaps always returns (fixed/hardcoded) dimensions of a US 8.5x11.5 inch piece of paper, regardless of the input PDF image.

sladen avatar Jun 16 '25 04:06 sladen

We're using ImageMagick-6..9.13-28 and identify returns expected results:

$identify -ping -format '%w %h\n' minimal.pdf 
595 842

urban-warrior avatar Aug 30 '25 22:08 urban-warrior