Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retina - Correlation between device pixel ratio and size of image?

I don't quite understand what the window.devicePixelRatio value is, and how it dictates what size image (2x, 3x, etc) I need for that device.

For instance, on an iMac 5K Retina (Late 2015), I'd expect the pixel ratio to be at least 3 or so, but it's actually 2, the same as an iPad Air and iPhone 6s. Does that mean it prefers a 2x bitmap? 3x?

like image 299
ffxsam Avatar asked May 03 '16 00:05

ffxsam


People also ask

What is retina display pixel ratio?

If you only want to target Retina displays, then setting min-device-pixel-ratio: 2 & min-resolution: 192dpi should be fine. However, Android supports a range of different dpi devices, including mdpi (160dpi), hdpi (240dpi), xhdpi (320dpi) and anywhere in between.

What is the pixel ratio of device?

Device pixel ratio is the the ratio between the physical pixels on a the hardware screen and the logical pixels (related to the physical size of the screen, also known as CSS resolution).

What resolution should images be for retina display?

Retina display is a high screen resolution of 4k or 5k, meaning a monitor resolution of 3840 x 2160 pixels for 4k and 5120 × 2880 for 5k. Retina images are images that can be viewed with great quality in these resolutions.

How many pixels per inch is Retina?

Apple external displays that have a Retina display Apple Pro Display XDR. Native resolution: 6016 x 3384 at 218 pixels per inch.


2 Answers

devicePixelRatio is the ratio between physical pixels and device-independent pixels (dips) on a given device. You can think of dips as what the display "acts" like.

For example: a non-retina 27" iMac has a width of 2560 physical pixels. Everything is displayed 1:1, so it's also 2560 dips wide, so the devicePixelRatio is 1.

On your retina 27" iMac, the width is 5120 physical pixels. But the display "acts" like it's only 2560 pixels wide, so that everything is shown at the same physical size as the non-retina iMac. Therefore, it's still 2560 dips wide, so the devicePixelRatio is 2 (5120 / 2560), and you would serve 2x images.

(You can look up what the dips values are for your system – if you have a retina display – by going to System Preferences > Displays > Display and switching the Resolution toggle to Scaled, then hovering over the different options. For Default, on the 5K iMac, it'll say "Looks like 2560 x 1440").

like image 117
daGUY Avatar answered Oct 18 '22 14:10

daGUY


To date, standard practice for graphics destined for Retina displays is still to provide an image that's twice the usual, non-Retina size.

Reminder: it is good "bandwidth hygiene" to serve an image only as large as needed for the current user's device size and resolution. Solutions to that are outside the scope of this question.

like image 44
Marlin Ouverson Avatar answered Oct 18 '22 16:10

Marlin Ouverson