As a 4K-monitor owner, I’m using OS-level scale of 200%, and I’ve encountered the need to guaranteedly display some raster images in web browser at their actual size without ANY scaling.
By actual size, I mean exact mapping of each single image pixel to single physical display pixel (as opposed to CSS pixels that are affected by OS-level or browser-level scaling that does not allow to view image at full available physical clarity/definition/sharpness of the display and also usually results in blur as for raster images).
Note that this has nothing to do with responsive images (displaying different images at predefined set of different pixel ratios in particular).
##Usecases
Some of usecases:
-
Web-based image viewer. Most of popular desktop image-viewers (e.g. XnView) have ability to display an image at its actual size without any scaling (and blur as a consequence of scaling) (in XnView, via menu “View → Zoom → 100%”). Web-based viewer should have a straightforward way to do the same.
-
Display tests:
- 2.1. for crystal inversion;
- 2.2. for chroma subsampling (1, [2] (http://www.avsforum.com/forum/166-lcd-flat-panel-displays/1381724-official-4-4-4-chroma-subsampling-thread.html), 3).
##Syntax
###Keyword for size values
On CSS level, this feature could be implemented as a new keyword like physical
applicable to both background-size
(for background images) and width
/ height
properties (for IMG
elements):
DIV {background-size: physical; }
IMG {
width: physical;
height: physical;
}
Or just IMG {size: physical}
with my proposal on width
/height
shorthand.
Instead of the physical
keyword, we could use real
, or natural
, or actual
, or anything else reasonable and clear enough (physical
just looks most clear for me).
###Property for per-element pixel ratio
Alternatively, we could have a CSS property like pixel-ratio
which value would correspond to JS’s window.devicePixelRatio
by default (for example, for scale of 200% in Windows, it would be equal to 2
) and could be set on per-element basis:
.example {pixel-ratio: 1; }
/* The element's size and other px-defined properties
now depend on this local pixel ratio instead of global
(defined by OS- or browser-level scale) pixel ratio. */
##JS drawbacks
Currently, we are forced to use JavaScript to calculate/restore an approximate compensated (!) image size based on window.devicePixelRatio
, but:
-
JavaScript does not work with JavaScript disabled;
-
resulting physical size based on calculated CSS size may be wrong (and is wrong at least in Opera 29 and IE 11 e.g. at Windows-level scale of 186% according to my tests) due to rounding errors caused by nature of floating-point math;
-
recalculating/restoring approximately something that browser already knows exactly looks at least somewhat unreasonable / suboptimal. We can do much better.
Thanks.