What is Pixel Density or PPI?
Pixel density is a calculation that returns the number of physical pixels per inch on a screen or display of a device. It’s often referred to as Pixels Per Inch or PPI.
Pixel density has become increasingly important as the resolution of screens has increased dramatically in the past several years. For example, the Apple iPhone XR has a high resolution screen with a pixel density of 323. In contrast, older XGA monitors had a PPI of around 85. Increased PPI can improve the quality of the viewing experience. Even when held closely, high PPI screens do not look pixelated (assuming that the image is of high enough quality to begin with).
What are the Key Inputs for Pixel Density Calculation?
As you might expect, the resolution and physical dimensions of the screen go into the pixel density calculation.
Resolution_width and resolution_height of the screen give you the number of physical pixels. It’s important to note that these are physical pixels, not logical or CSS pixels.
The physical width and height of the screen converted into inches is in the denominator.
For a more detailed explanation, you can visit here.
How Does Device Detection Calculate Pixel Density?
A device detection system like WURFL makes pixel density easy to determine for web developers. The first step is to accurately detect the device down to the actual manufacturer and model. This description of how device detection works give you high level WURFL will identify the device from the server side using the user agent string.
It’s important to point out that most ua parsers or sniffers are not sophisticated or accurate enough to determine the device and its resolution and physical screen size. However, a fully fledged device detection solution like WURFL contains over 500 properties or capabilities of a device.
With the latest release of WURFL, we have made calculating pixel density easier for developers. Before, they could pull the necessary WURFL capabilities, return them to their application and make their own PPI calculation. Now, we have combined them in an easy-to-return capability called pixel_density
. The result returned is an integer that developers can use their applications.
Why is Pixel Density a Virtual Capability?
WURFL contains two categories of capabilities: static and virtual.
Static capabilities describe device and browser properties that do not (normally) change. For instance, a device’s resolution_width will not change over time. Static properties can be stored in memory by the API, readily available for the next fast look-up. In the case of pixel_density
, the resolution and physical dimensions are static capabilities.
Virtual capabilities return a property whose value is based on the evaluation/calculation of other static capabilities or further inspection of parameters found in the HTTP request. For example, pixel_density
takes the static capabilities of resolution and physical dimensions and calculates the PPI during run-time.
It should be noted that virtual capabilities like pixel_density
have a different method syntax than static capabilities. In Java, a following method would return pixel density:
device.getVirtualCapability(‘pixel_density’)
Consult WURFL documentation for your particular platform’s syntax.
How Can Developers Use Pixel Density or PPI?
While it has many use cases, pixel_density
is useful when optimizing, resizing, or reformatting images. Pixel_density
will tell you how far you can reduce the dimensions or compression of an image before visual quality is impacted.
Give pixel density a trial by contacting ScientiaMobile and adding pixel_density to your WURFL capabilities.