-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intrinsic dimensions #85
Comments
I don't want to derail the conversation from the problem you're trying to address (re-layouts... for which an 'h' descriptor sounds like a pretty nice solution). But... Edit: snip, as I then went on to derail the discussion (: Moved to #86. As an author, being able to add an optional 'h' to one of the sources in order to define the aspect ratio and prevent reflows sounds like an easy win. So this SGTM. |
@eeeps - I think this is an important discussion, but can you please open a new issue regarding that? (since it's a separate subject from intrinsic dimensions calculation). It'd enable to keep both topics' discussions on subject. Thanks :) |
srcset does provide height descriptor [1]. That said, one of my takeaways from the resp-img meetup back in September was that But even with that aside, isn't the intent of srcset [1] http://www.w3.org/html/wg/drafts/srcset/w3c-srcset/#additions-to-the-img-element |
@igrigorik Don't be confused by the surface similarity with HTML's |
@tabatkins ah, I see... Indeed, didn't catch that. Knowing that, the examples make a lot more sense - #5 in particular. FWIW, it may be worth calling out this difference more explicitly in the spec. Since I'm two steps behind, let me see if I grok the proposal via an explicit example: <picture>
<source sizes="(max-width: 30em) 100%, (max-width: 50em) 50%, calc(33% - 100px)"
srcset="pic400.jpg 400w 200h, pic800.jpg 800w, pic1200.jpg 1200w">
<img src="pic400.jpg" alt="The president giving an award.">
</picture> Let's say my device max-width is 30em (with 16px default font size) and my DPR is 2.0, then:
Does that look about right? P.S. Still need to grok how this would also work with sizes + w/h (ala #86). |
Yup, that's exactly right. |
Do we need this? Traditionally you would just use width/height attributes on the img element. Is that not good enough? |
Hmm. Nevermind, that doesn't work for art direction. |
Yeah. This bug would be resolved with @tabatkins's proposal |
I think it is slightly cryptic that a hight descriptor on one image source magically sets the aspect ratio for other image sources also. I don't think that is especially clear for authors. From the example above, it looks to me like the height descriptor is missing from some of the sources. Moreover, the calculated aspect ratio might not exactly match the other image's actual aspect ratios, due to rounding, resulting in the intrinsic height being slightly off. I think if we want to specify the aspect ratio for all the sources, it would be clearer to have a separate attribute (still subject to rounding). Or use the height descriptor for each image source individually. |
Mandating authors to specify height on every image can become cumbersome quick. All in all, I think the best would be to conclude ratio from first tuple, and override it with more specific ones if provided by author, but since it's a matter of authoring convenience (and I'm far from being an expert on the subject or a day-to-day author), I'm not hung up on any particular syntax as long as the browser can conclude the intrinsic size. |
Alright, after a bunch of discussion in the IRC channel, it’s looking like the prevailing opinion is this: for situations where the aspect ratio of all sources in a In the event that the sources have differing aspect ratios, adding in-syntax overrides gets clunky in a hurry. We have a handful of votes for relegating differing aspect ratios to different |
100% agreed on that approach. On Wed, Feb 26, 2014 at 1:17 PM, Mat Marquis notifications@github.comwrote:
|
LGTM. The dash should be omitted in the attribute name to match HTML's naming convention. If the value is invalid, the attribute should just be ignored. |
Hmm, thinking about this some more, this only helps when using sizes and width descriptors. If you use density descriptors instead, there's no way to set the intrinsic width/height of the source. We could add width/height attributes for that case maybe? |
Count me as slightly opposed, especially if/when #86 is addressed and there's a second reason for <picture>
<source
sizes="contain"
srcset="large.jpg 1024w 768h,
small.jpg 512w 384h"
aspectratio="1024/768" />
<img src="small.jpg" alt="¡Obama mambo!" />
</picture> ...just copying over an |
Why not <picture>
<source srcset="small.jpg 512w 384h 1x, large.jpg 1024w 768h 2x" />
<img src="small.jpg" alt="Biden doing the shim sham" />
</picture> It feels weird to me to set an intrinsic |
I also dislike setting @eeeps I think if you're providing both |
Confusion how? |
@yoavweiss because people are used to if we used different attribute names, i'd feel a lot more comfortable with it. i just think |
The intrinsic width and height are the width and height that are used for display (unless overridden by CSS). In @eeeps 's example above, the width/height used for rendering for either image would be 512x368 CSS pixels. I can buy that aspectratio/width/height attributes are more confusing or clunky than width/height descriptors, sure. |
It seems like there are tradeoffs with each option, but here's where I think we're at:
I think that about covers it, but tell me if I'm wrong. Given these options, from an author POV, I would prefer 1 because it involves the least amount of duplication and figuring-stuff-out, keeps But I am but one man... |
That's about right. I think most authors are not going to understand the details here when they write their markup. So that suggests that we should make it hard to do something that doesn't make sense. Having more attributes to choose from gives more opportunities for doing something nonsensical (such as including all attributes and all descriptors, because, hey, they're available, that means they have to be filled in, right?). For this reason I'm leaning towards (2). Note that it doesn't have to be more work for the author, it's enough to specify w/h for one of the image sources. |
Having just misunderstood the details myself, I agree! I wasn't clear until reading @zcorpan's comment that intrinsic dimensions and resource dimensions were different things. Frankly I stopped using Reading up, I think I understand now that "intrinsic dimensions" are the display dimensions before CSS.
Practically, for authors, the only reason to specify intrinsic dimensions in markup rather than have the browser infer them from the resource dimensions once the resource has loaded (as is my habit) is to prevent reflows that might occur when image resources finish loading after the CSS. Do I have all that right? If so, I agree with @zcorpan on (2). The whole concept of specifying intrinsic height, width, and/or aspect ratio separately from resource dimensions is very confusing — better to only have to worry about the latter. Not sure how #107 figures in with this though? |
It's probably a good idea to fix this at the same time as fixing #86 so that we don't introduce a syntax that does one thing and later reuse that syntax to also do something else. |
I actually like the idea of having an attribute called I also don't think, that this attribute doesn't work with x descriptors. While there are possibilities to define this with markup. We simply need either the width or the height. And for this we could re-use the width declared on the But for the actual practice, this isn't important. What is actually important is that the attribute works in conjunction with CSS, where the author can declare a specific CSS side (mostly width) and the corresponding other side (height) is automatically calculated (as long as the CSS value is either initial/auto), so that the browser can occupy the space before the image is loaded: <img
style="width: 300px; height: auto;"
aspectratio="3"
srcset="600x200.jpg 2x" src="300x100.jpg" /> This really means we only need an aspectratio attribute, nothing more. |
In my opinion we should do what has the most chance of being used correctly most of the time even when the Web developer doesn't understand the details. In your example you don't need the aspectratio attribute at all, you can just say |
@zcorpan Here are 3 different examples: <picture>
<source
srcset="200x300.jpg 1x, 400x600.jpg 2x"
aspectratio="0.666" />
<img
style="width: 300px; height: auto;"
aspectratio="3"
srcset="600x200.jpg 2x" src="300x100.jpg" />
</picture>
<img
style="width: 100%; height: auto;"
aspectratio="2"
srcset="300x150.jpg 300w, 600x300 600w" />
<img
style="width: 100%; height: auto;"
srcset="300x150.jpg 300w 150h, 600x300 300h 600w" /> And I think this is quite easy. The developer will know what aspectratio means and at least if one side is defined the other one can be calculated. In case an x descriptor is used and both sides are auto/initial the dimension can't be calculated, but I'm fine with this. |
IMHO, there's one more reason to not rely on the
When what we want is to (gently) push authors to write this:
So, it makes it easier to get the art direction concern bleed into the wrong feature. Using
If you try to use |
This issue came up recently on www-style: |
https://lists.w3.org/Archives/Public/public-respimg/2016Nov/0000.html (thread continues in December) |
I am a little disappointed this is still a thing, wanted to replace an old responsive-lazy-image implementation i wrote with a standard loading="lazy" method, just to find out it cant accomplish different aspect ratios. Why cant it simply be like this: <picture>
<source media="(min-width: 640px)" srcset="large-src.jpg" width="600" height="300" />
<source srcset="small-src.jpg" width="400" height="300" />
<img src="large-src.jpg" loading="lazy" width="400" height="300" />
</picture> So the matched source would be able to override the existing widht/height attribute? I cant see any problem with that and it would be much more intuitive to use. Should @container-queries be taken into account as well? <picture>
<source container="(min-width: 640px)" media="(min-width: 640px)" srcset="large-src.jpg" width="600" height="300" />
<source srcset="small-src.jpg" width="400" height="300" />
<img src="large-src.jpg" loading="lazy" width="400" height="300" />
</picture> Please make this happen so i can remove all my custom implementations that are a real p*** in my a** to maintain. |
|
Awesome! Chromium already returns "number" on this assertions: Firefox seems to lack support for width/height as well as aspectRatio though... Looking forward to this, thanks for your reply. |
While working on yoavweiss@d0fda08 to fix #82 I realized that the browser doesn't have enough data with current syntax to get the intrinsic dimensions of the image, only its intrinsic width. The height remains a mystery until the image is downloaded (or until Layout says otherwise).
AFAICT, in order to resolve it, we need to add some data in the syntax regarding height. I propose the following:
Now, I might have missed something, or the above proposal may be bad. Let me know if you think that's the case.
The text was updated successfully, but these errors were encountered: