Calculating image size in inches or dpi from pixels using php

若如初见. 提交于 2019-12-19 10:03:33

问题


I need to calculate an approximate image size in inches assuming 300dpi.

I have a target image size in mind, and i want to show the user if the image they have uploaded is adequate, or will need to be stretched, and offer various conditional messages based off of this.

I already have the height and width in pixels, just need to know the math i guess.


回答1:


DPI = "dots per inch". One dot = one pixel.

300 pixels in 300 dpi: 1 inch. You can work it out :-)




回答2:


Given that dots == pixels:

size in inches = size in pixels / dots per inch

so if you have an image that's 900 pixels wide, at 300 dpi it will be printed at 3 inches.



来源:https://stackoverflow.com/questions/4223975/calculating-image-size-in-inches-or-dpi-from-pixels-using-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!