Last active
December 20, 2015 13:39
-
-
Save ljmccarthy/6140389 to your computer and use it in GitHub Desktop.
Calculate display PPI (pixels per inch) given resolution, aspect ratio and diagonal size.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate display PPI (pixels per inch) given resolution, aspect ratio and diagonal size. | |
# Luke McCarthy 2013-08-02 | |
import math | |
def display_ppi(resolution, aspect_ratio, size_inches): | |
res_h, res_v = resolution | |
aspect_h, aspect_v = aspect_ratio | |
theta = math.atan(float(aspect_v) / aspect_h) | |
width = math.cos(theta) * size_inches | |
height = math.sin(theta) * size_inches | |
return (res_h / width, res_v / height) | |
if __name__ == '__main__': | |
resolution = (1920, 1080) | |
aspect_ratio = (16, 9) | |
monitor_sizes = [5, 7, 10, 18.5, 21.5, 24, 27, 32, 40, 50] | |
for size in monitor_sizes: | |
print '%.1f" @ %dx%d -> %.f PPI' % ( | |
size, resolution[0], resolution[1], display_ppi(resolution, aspect_ratio, size)[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment