WICG / intrinsicsize-attribute

Proposal to add an intrinsicsize attribute to media elements
Apache License 2.0
93 stars 14 forks source link

intrinsicsize + the `Width` Client Hint #7

Open eeeps opened 6 years ago

eeeps commented 6 years ago

Use case: when sending the Width Client Hint, I want to be able to specify aspect-ratios instead of sizes, just as I can with srcset, as discussed in #3. e.g.:

<img src="variable-width.jpg" sizes="25vw" intrinsicsize="16x9" />

[✂️ edit! I worked through a whole example from a false premise! doh! ✂️]

Naively, seems like you should just be able to apply the intrinsic ratio from intrinsicsize to the sizes width to get a density-corrected intrinsic height. But, given that sizes only ends up setting the density-corrected intrinsic width of the image as a side effect, and in conjunction with w descriptors... how could this work?

cc: @yoavweiss @igrigorik @colinbendell

tabatkins commented 6 years ago

Width doesn't want to have anything whatsoever to do with sizes; that's the displayed width on the page. Width is asking for an image with a particular pixel width, aka the w value, assuming I'm reading the spec correctly.

Assuming that w and intrinsicsize are both used, you can then infer a desired pixel height and send that along in a future CH, yes.

eeeps commented 6 years ago

Width doesn't want to have anything whatsoever to do with sizes

Chrome doesn’t send Width unless it has a sizes to calculate it from. It attaches Width = the sizes width × window.devicePixelRatio, to requests.

Assuming that w and intrinsicsize are both used, you can then infer a desired pixel height and send that along in a future CH

Client Hints are meant to be used instead of srcset (and xs and ws), not in conjunction with it.

tabatkins commented 6 years ago

Chrome doesn’t send Width unless it has a sizes to calculate it from. It attaches Width = the sizes width × window.devicePixelRatio, to requests.

Ah, ok. This derivation of the Width value isn't explained anywhere in the spec, so I wasn't aware.


Anyway, I'm also coming to believe we need to attach more intrinsic importance to sizes here - sizes+w happens to result in an image with a naturalWidth matching sizes if the w descriptor accurately matches the image. If it doesn't, then the density we determine is off, and the resulting naturalWidth (determined from the resource's actual size, divided by density) doesn't match sizes.

So sizes probably should be interpreted as actually setting the intrinsic width of the image. Has this accidentally slipped into the spec anywhere? With this, we can go ahead and assume that sizes expresses some useful information, even if the w descriptor isn't being used.