Skip to content

Commit

Permalink
Allow an image to indicate its own density and correct its intrinsic …
Browse files Browse the repository at this point in the history
…size.

See https://discourse.wicg.io/t/proposal-exif-image-resolution-auto-and-from-image/4326/24

This proposal allows using EXIF or other metadata to determine an image's
default resolution, which may be different from the requested resolution
in srcset/image-set, or from the default of 1dppx.

The use-case is, for example, allowing serving low-density placeholder in poor
network conditions without affecting layout.

When an image indicates its intrinsic density-corrected size, that indication
is "stronger" than the requested density (current pixel density). This allows, for example, serving a regular 1x image when a 2x image is requested by srcset, allowing for correct presentation of content that contains that information.

The WICG proposal defines that in detail - using size+resolution from EXIF
when their values are matching.
  • Loading branch information
noamr committed May 26, 2020
1 parent cd33503 commit 0f651cb
Showing 1 changed file with 51 additions and 11 deletions.
62 changes: 51 additions & 11 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -27246,12 +27246,20 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</code

<p>Each <span>image request</span> has a <dfn>current pixel density</dfn>, which must initially be undefined.</p>

<p>When an <code>img</code> element has a <span>current pixel density</span> that is not 1.0, the
element's image data must be treated as if its resolution, in device pixels per <span
data-x="'px'">CSS pixels</span>, was the <span>current pixel density</span>. The image's
<dfn>density-corrected intrinsic width and height</dfn> are the <span data-x="intrinsic
dimensions">intrinsic width and height</span> after taking into account the <span>current pixel
density</span>.</p>
<p>Each <code>img</code> element has <dfn>preferred density-corrected dimensions</dfn>,
which must initially be undefined.</p>

<p>To determine the a <dfn>density-corrected intrinsic width and height</dfn> of
<code>img</code> element <var>img</var>:
<ol>
<li><p>Set <var>dim</var> to <var>img</var>'s <span>intrinsically defined density-corrected
dimensions</span>.

<li><p>If <var>dim</var> is not undefined, return <var>dim</var>.</p></li>
<li><p>Set <var>dim</var> to <var>img</var>'s <span>intrinsic dimensions</span>.</p></li>
<li><p>Divide <var>dim</var>'s width and height by <var>img</var>'s <span>current pixel density</span>
<li><p>Return <var>dim</var>.
</ol>

<p class="example">For example, if the <span>current pixel density</span> is 3.125, that means
that there are 300 device pixels per <span data-x="'in'">CSS inch</span>, and thus if the image
Expand Down Expand Up @@ -27798,13 +27806,15 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</code

<ol>
<li><p>If the user agent is able to determine <var>image request</var>'s image's width and
height, and <var>image request</var> is <span>pending request</span>, set <var>image
request</var>'s <span data-x="img-req-state">state</span> to <span data-x="img-inc">partially
available</span>.</p></li>
height, and <var>image request</var> is <span>pending request</span>,
<span data-x="update the image metadata"> update the <code>img</code> metadata</span> and set
<var>image request</var>'s <span data-x="img-req-state">state</span> to
<span data-x="img-inc">partially available</span>.</p></li>

<li><p>Otherwise, if the user agent is able to determine <var>image request</var>'s image's
width and height, and <var>image request</var> is <span>current request</span>, update the
<code>img</code> element's presentation appropriately and set <var>image request</var>'s
width and height, and <var>image request</var> is <span>current request</span>,
<span data-x="update the image metadata"> update the <code>img</code> metadata</span>, and update
the <code>img</code> element's presentation appropriately and set <var>image request</var>'s
<span data-x="img-req-state">state</span> to <span data-x="img-inc">partially
available</span>.</p></li>

Expand Down Expand Up @@ -27894,6 +27904,35 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</code
<li><p>Let the <code>img</code> element's <span>pending request</span> be null.</p></li>
</ol>

<h6>Updating the image metadata</h6>
<p>When asked to <dfn>update the image metadata</dfn> for a given <code>img</code>, user agents must do the following:
<ol>
<li><p>Let the following <dfn>density-correction metadata values</dfn> be defined for <code>img</code>, initially set to underfined:</p>
<ul>
<li>Preferred Width</li>
<li>Preferred Height</li>
<li>Horizontal Resolution</li>
<li>Vertical Reoslution</li>
<li>Resolution Unit</li>
</ul>
<li><p>Determine <code>img</code>'s <span>density-correction metadata values</code> from <code>img</code>.</p>

<p class="note">These values <!--non-normative-->should correspond to EXIF tags <code>PixelXDimension</code>,
<code>PixelYDimension</code>, <code>XResolution</code>, <code>YResolution</code> and <code>ResolutionUnit</code>.
However, they <!--non-normative-->may also be implemented by other metadata standards such as XMP.</p>
</li>

<li><p>If the user agent was not able to determine all of <span>density-correction metadata values</span> for <code>img</code>,
return.</p></li>
<li><p>If any of <code>img</code>'s <span>density-correction metadata values</span> is 0. return.</li>
<li><p>If <code>img</code>'s <code>resolution unit</code> is different from <code>inches</code>, return.</p></li>
<li><p>If <code>img</code>'s width divided by <code>horizontal resolution</code> does not equal to <code>img</code>'s
<code>preferred width</code>, return.</p></li>
<li><p>If <code>img</code>'s height divided by <code>vertical resolution</code> does not equal to <code>img</code>'s
<code>preferred height</code>, return.</p></li>
<li><p>Set <code>img</code>'s <span>preferred density-corrected dimensions</span> to <code>img</code>'s
<code>preferred width</code> and <code>preferred height</code>.
</ol>

<h6>Selecting an image source</h6>

Expand Down Expand Up @@ -121464,6 +121503,7 @@ INSERT INTERFACES HERE
Nikki Bee,
Noah Mendelsohn,
Noah Slater,
Noam Rosenthal,
Noel Gordon,
Nolan Waite,
NoozNooz42,
Expand Down

0 comments on commit 0f651cb

Please sign in to comment.