Search code examples
imagemagickdpippi

ImageMagick shows the same print size for 300 and 72 DPI images?


I have two images, both are 2550 by 3300 pixels, which is 8.5 by 11 inches if printed at 300 DPI, but whereas the first image is 300 DPI, the second is only 72 DPI.

The official help page of the identify command shows how to get the image's print size in inches, and if we are going to print the image at 300 DPI, the command seems to be

magick identify -format "%[fx:w/300] by %[fx:h/300] inches" document.png

But why does it returns the same print size for both images?

magick identify -format "%f: %wx%h pixels, %xx%y dots per inch, %[fx:w/300] by %[fx:h/300] inches at 300 DPI\n" "letter*.jpg"
letter-072-dpi.jpg: 2550x3300 pixels,  72x72  dots per inch, 8.5 by 11 inches at 300 DPI
letter-300-dpi.jpg: 2550x3300 pixels, 300x300 dots per inch, 8.5 by 11 inches at 300 DPI

I was sure that because the images have different DPI, their print sizes should be different as well, that is, 8.5 by 11 inches for the 300 DPI image, but something different for the 72 DPI one. It seems I was wrong?

An importand update: I have discovered that magick identify -verbose provides print size automatically and correctly:

Print size: 8.5x11
Print size: 35.4167x45.8333

But how to get these print sizes without using -verbose?

Reply to Mark:

identify: Expected operand at 'x' @ error/fx.c/GetOperand/2365.
identify: Expected operand at 'x' @ error/fx.c/TranslateExpression/2664.
identify: Expected operand at 'x' @ error/fx.c/TranslateExpression/2664.
letter-072-dpi.jpg:  by 
letter-300-dpi.jpg:  by 

Solution

  • You have hard-coded the 300dpi into your calculation, and are ignoring the dpi embedded in the actual image. Try:

    magick identify -format "%f: %wx%h pixels, %xx%y dots per inch, %[fx:w/resolution.x] by %[fx:h/resolution.y] inches at embedded DPI\n" "letter*.jpg"