Is it at all possible to detect a PNG's DPI with vips?
demitrious-tom opened this issue · 3 comments
demitrious-tom commented
Per the example here:
I am trying to detect if a PNG has a certain DPI for use in a validation, is that something that is currently possible with ruby-vips?
jcupitt commented
Hi @demitrious-tom,
You can read the x and y resolution, eg.:
john@kiwi:~/pics$ irb
irb(main):001:0> require 'vips'
=> true
irb(main):002:0> x = Vips::Image.new_from_file("k2.png")
=> #<Image 1450x2048 uchar, 3 bands, srgb>
irb(main):003:0> x.get "xres"
=> 2.835
irb(main):004:0>
The number is always pixels per millimetre.
demitrious-tom commented
Just to make sure I understand this. This calculation is not the same as PPI (other than the fact it's in cm), as it does not consider the size of some subsequent print location? This calculation expresses the density (I don't really have the required technical vocabulary to word this question well) of the pixels printed?
demitrious-tom commented
Actually just got a chance to run a few tests and this does indeed appear to do what I was asking, thanks so much!!!. :)