Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
demitrious-tom opened this issue Jul 19, 2022 · 3 comments
Open

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

demitrious-tom opened this issue Jul 19, 2022 · 3 comments

Comments

@demitrious-tom
Copy link

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?

@jcupitt
Copy link
Member

jcupitt commented Jul 19, 2022

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
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants