How to find pixels per inch (PPI) using ImageMagick

前端 未结 4 786
北恋
北恋 2021-02-10 04:26

I can get PPI for a JPEG image using the following command:

$ identify -format \"%w x %h %x x %y\" mypic.jpg 
1600 x 1200 72 PixelsPerInch x 72 PixelsPerInch


        
相关标签:
4条回答
  • 2021-02-10 05:10

    The resolution and units used are stored in the file, so if the resolution is stored in PixelsPerCentimeter, that's how identify will display it. There isn't a way to do the conversion automatically through identify. But it's just cm to inch conversion math:

    PixelsPerInch = PixelsPerCentimeter * 2.54
    
    0 讨论(0)
  • 2021-02-10 05:22

    1 inch =~ 2.54 cm. So it is trivial to convert between the two.

    0 讨论(0)
  • 2021-02-10 05:24

    You can use the fx operator and some smart formatting in the output of identify like this:

    identify -format "%[fx:int(resolution.x*2.54)]" image.png
    299
    

    Of course, the true joy of this is that it is platform-independent, so you don't have to shell out to dc on OS X and Linux, or do whatever muppetry is required on Windows to do the maths.

    0 讨论(0)
  • 2021-02-10 05:25

    You can simply add the option

    -units PixelsPerInch
    
    0 讨论(0)
提交回复
热议问题