libvips/ruby-vips

Is it at all possible to detect a PNG's DPI with vips?

demitrious-tom opened this issue · 3 comments

Per the example here:

https://www.printful.com/blog/everything-you-need-to-know-to-prepare-the-perfect-printfile/#1_You_resized_a_low-quality_image_lowering_its_DPI_even_more

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?

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.

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?

Actually just got a chance to run a few tests and this does indeed appear to do what I was asking, thanks so much!!!. :)