Skip to content

Commit d5179c1

Browse files
committed
Allow an image to indicate its own density and correct its intrinsic 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.
1 parent cd33503 commit d5179c1

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

source

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27246,12 +27246,19 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</code
2724627246

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

27249-
<p>When an <code>img</code> element has a <span>current pixel density</span> that is not 1.0, the
27250-
element's image data must be treated as if its resolution, in device pixels per <span
27251-
data-x="'px'">CSS pixels</span>, was the <span>current pixel density</span>. The image's
27252-
<dfn>density-corrected intrinsic width and height</dfn> are the <span data-x="intrinsic
27253-
dimensions">intrinsic width and height</span> after taking into account the <span>current pixel
27254-
density</span>.</p>
27249+
<p>Each <code>img</code> element has <dfn>preferred density-corrected dimensions</dfn>,
27250+
which must initially be undefined.</p>
27251+
27252+
<p>To determine the a <dfn>density-corrected intrinsic width and height</dfn> of
27253+
<code>img</code> element <var>img</var>:
27254+
<ol>
27255+
<li><p>Set <var>dim</var> to <var>img</var>'s <span>preferred density-corrected dimensions</span>.
27256+
27257+
<li><p>If <var>dim</var> is not undefined, return <var>dim</var>.</p></li>
27258+
<li><p>Set <var>dim</var> to <var>img</var>'s <span>intrinsic dimensions</span>.</p></li>
27259+
<li><p>Divide <var>dim</var>'s width and height by <var>img</var>'s <span>current pixel density</span>
27260+
<li><p>Return <var>dim</var>.
27261+
</ol>
2725527262

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

2779927806
<ol>
2780027807
<li><p>If the user agent is able to determine <var>image request</var>'s image's width and
27801-
height, and <var>image request</var> is <span>pending request</span>, set <var>image
27802-
request</var>'s <span data-x="img-req-state">state</span> to <span data-x="img-inc">partially
27803-
available</span>.</p></li>
27808+
height, and <var>image request</var> is <span>pending request</span>,
27809+
<span data-x="update the image metadata"> update the <code>img</code> metadata</span> and set
27810+
<var>image request</var>'s <span data-x="img-req-state">state</span> to
27811+
<span data-x="img-inc">partially available</span>.</p></li>
2780427812

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

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

27906+
<h6>Updating the image metadata</h6>
27907+
<p>When asked to <dfn>update the image metadata</dfn> for a given <code>img</code>, user agents must do the following:
27908+
27909+
<ol>
27910+
<li><p>Attempt to read <dfn data-x-href="https://www.exif.org/Exif2-2.PDF">EXIF</dfn> metadata embedded in the image, as defined in the
27911+
image codec.</p></li>
27912+
<li><p>If <code>img</code> does not have any <span>EXIF</span> metadata, return.</p></li>
27913+
<li><p>Let <code>img</code>'s <code>preferred width</code> correspond to the value of <span>EXIF</span> tag <code>PixelXDimension</code>
27914+
(<code>0xa002</code>). If <code>preferred width</code> is not a number between <code>1</code> and <code>65535</code>, return.</p></li>
27915+
<li><p>Let <code>img</code>'s <code>preferred height</code> correspond to the value of <span>EXIF</span> tag <code>PixelYDimension</code>
27916+
(<code>0xa003</code>).</p></li> If <code>preferred width</code> is not a number between <code>1</code> and <code>65535</code>, return.</p></li>
27917+
<li><p>Let <code>img</code>'s <code>resolution unit</code> correspond to the value of <span>EXIF</span> tag <code>ResolutionUnit</code>
27918+
(<code>0x0128</code>). If <code>resolution unit</code> is not <code>Inches</code> (<code>2</code>, return.</p></li>
27919+
<li><p>Let <code>img</code>'s <code>horizontal resolution</code> correspond to the value of <span>EXIF</span> tag <code>XResolution</code>
27920+
(<code>0x011a</code>).</p> If <code>horizontal resolution</code> is not a number between <code>1</code> and <code>65535</code>, return.</p></li>
27921+
<li><p>Let <code>img</code>'s <code>vertical resolution</code> correspond to the value of <span>EXIF</span> tag <code>YResolution</code>
27922+
(<code>0x011b</code>).</p> If <code>vertical resolution</code> is not a number between <code>1</code> and <code>65535</code>, return.</p></li>
27923+
<li><p>If <code>img</code>'s width in <code>inches</code> divided by <code>horizontal resolution</code> is equal to <code>img</code>'s
27924+
<code>preferred width</code>, and <code>img</code>'s height in <code>inches</code> divided by <code>vertical resolution</code> is equal to <code>img</code>'s width,
27925+
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></p></li>.
27926+
</ol>
2789727927

2789827928
<h6>Selecting an image source</h6>
2789927929

@@ -121464,6 +121494,7 @@ INSERT INTERFACES HERE
121464121494
Nikki Bee,
121465121495
Noah Mendelsohn,
121466121496
Noah Slater,
121497+
Noam Rosenthal,
121467121498
Noel Gordon,
121468121499
Nolan Waite,
121469121500
NoozNooz42,

0 commit comments

Comments
 (0)