Skip to content

Commit c573727

Browse files
committed
[css-images-4] Add type() to image-set(). #656
1 parent 90a35af commit c573727

File tree

1 file changed

+99
-16
lines changed

1 file changed

+99
-16
lines changed

css-images-4/Overview.bs

+99-16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Previous Version: https://www.w3.org/TR/2012/WD-css4-images-20120911/
1919
Ignored Terms: <offset>, background positioning area, border image area, <meetorslice>, <ending-shape>, Map, <image>, invalid image, invalid images, concrete object size, linear-gradient(), radial-gradient(), intrinsic dimensions, default object size, CSS
2020
Ignored Vars: H, P
2121
Include Can I Use Panels: yes
22+
Default Highlight: css
2223
</pre>
2324

2425
<pre class=link-defaults>
@@ -149,7 +150,7 @@ Note: No change from [[css3-images]].
149150
-->
150151

151152

152-
Resolution Negotiation: the ''image-set()'' notation {#image-set-notation}
153+
Resolution/Type Negotiation: the ''image-set()'' notation {#image-set-notation}
153154
--------------------------------------------------------------------------
154155

155156
Delivering the most appropriate image resolution for a user's device can be a difficult task.
@@ -174,31 +175,76 @@ Resolution Negotiation: the ''image-set()'' notation {#image-set-notation}
174175

175176
<pre class='prod'>
176177
<dfn caniuse="css-image-set">image-set()</dfn> = image-set( <<image-set-option>># )
177-
<dfn>&lt;image-set-option></dfn> = [ <<image>> | <<string>> ] <<resolution>>
178+
<dfn>&lt;image-set-option></dfn> = [ <<image>> | <<string>> ]
179+
[ <<resolution>> || type(<<string>>) ]
178180
</pre>
179181

180-
Issue: We should add "w" and "h" dimensions as a possibility, and a "format()" function,
182+
Issue: We should add "w" and "h" dimensions as a possibility
181183
to match the functionality of HTML's <a element>picture</a>.
182184

185+
Each <<string>> inside ''image-set()'' represents a <<url>>.
186+
183187
The ''image-set()'' function can not be nested inside of itself,
184188
either directly
185189
or indirectly
186190
(as an argument to another <<image>> type).
187191

188-
Issue: Is this restriction needed?
189-
190-
Each <<string>> inside ''image-set()'' represents a <<url>>.
191-
192-
Every <<image-set-option>> in a given ''image-set()'' must have a different <<resolution>>,
193-
or else the function is invalid.
192+
Each <<image-set-option>> defines a possible image for the ''image-set()'' function to represent,
193+
composed of three parts:
194+
195+
* An image reference (required).
196+
This can be a URL,
197+
or a CSS generated image,
198+
such as a ''linear-gradient()''.
199+
200+
* A <<resolution>> (optional).
201+
This is used to help the UA decide which <<image-set-option>> to choose.
202+
If the image reference is for a raster image,
203+
it also specifies the image's <a spec=css-images-4>intrinsic resolution</a>,
204+
overriding any other source of data that might supply an [=intrinsic resolution=].
205+
206+
If not specified,
207+
it behaves as ''1x'' for the purpose of selecting which <<image-set-option>> to use.
208+
It also <em>defaults</em> the image's [=intrinsic resolution=] to ''1x'',
209+
but if some other source of data supplies an [=intrinsic resolution=],
210+
that resolution must be honored instead.
211+
212+
* A <dfn function for=image-set() lt=type()>type( <<string>> )</dfn> function (optional),
213+
specifying the image's MIME type in the <<string>>.
214+
215+
If the <<string>>,
216+
when parsed as a [=valid MIME type string=],
217+
is either not valid,
218+
or is valid but doesn't specify a supported image format,
219+
the <<image-set-option>> does not define a valid option.
220+
(This has no effect on the validity of the ''image-set()'' function.)
221+
222+
It does not have any effect on the image itself;
223+
an <<image-set-option>> like <code highlight=css>url("picture.png") 1x format("image/jpeg")</code> is valid,
224+
and if chosen will display the linked PNG image,
225+
even tho it was declared to be a JPEG.
226+
227+
It not specified,
228+
it has no effect on the <<image-set-option>>.
229+
230+
231+
An ''image-set()'' function contains a list of one or more <<image-set-option>>s,
232+
and must select only one of them
233+
to determine what image it will represent:
234+
235+
1. First, remove any <<image-set-option>>s from the list
236+
that specify an unknown or unsupported MIME type in their ''type()'' value.
237+
2. Second, remove any <<image-set-option>>s from the list
238+
that have the same <<resolution>> as a previous option in the list.
239+
3. Finally, among the remaining <<image-set-option>>s,
240+
make a UA-specific choice of which to load,
241+
based on whatever criteria deemed relevant
242+
(such as the resolution of the display,
243+
connection speed,
244+
etc).
245+
4. The ''image-set()'' function then represents the <<image>>
246+
of the chosen <<image-set-option>>.
194247

195-
UAs must make a UA-specific choice of which <<image-set-option>> to load,
196-
based on whatever criteria they find relevant
197-
(such as the resolution of the display,
198-
connection speed,
199-
etc).
200-
The ''image-set()'' then represents the image associated with the URL of that choice.
201-
The image's <a spec=css-images-4>intrinsic resolution</a> is the resolution associated with that choice.
202248
UAs <strong>may</strong> change which <<image-set-option>> they wish to use for a given ''image-set()''
203249
over the lifetime of the page,
204250
if the criteria used to determine which option to choose change significantly enough to make it worthwhile in the UA's estimation.
@@ -217,6 +263,43 @@ Resolution Negotiation: the ''image-set()'' notation {#image-set-notation}
217263
</pre>
218264
</div>
219265

266+
<div class='example'>
267+
This example shows use of the ''type()'' function
268+
to serve multiple versions of the same image
269+
in both new, higher-quality formats,
270+
and older, more widely-supported formats:
271+
272+
<pre>
273+
background-image: image-set( "foo.avif" type("image/avif"),
274+
"foo.jpg" type("image/jpeg") );
275+
</pre>
276+
277+
Note that the AVIF image is given first;
278+
since both images have the same resolution
279+
(defaulting to ''1x'' since it's unspecified),
280+
the JPEG image,
281+
coming second,
282+
is automatically dropped in UAs that support AVIF images.
283+
284+
In older UAs, however,
285+
the AVIF image is ignored
286+
(because the UA knows it doesn't support <code>"image/avif"</code> files),
287+
and so the JPEG is chosen instead.
288+
</div>
289+
290+
<div class=example>
291+
Raster images can be mixed with vector images,
292+
or even CSS generated images.
293+
294+
For example, in this code snippet
295+
a high-resolution image with subtle details is used on screens that can do it justice,
296+
while an ordinary CSS ''linear-gradient()'' is used instead for low-resolution situations:
297+
298+
<pre>
299+
background-image: image-set( linear-gradient(cornflowerblue, white) 1x,
300+
url("detailed-gradient.png") 3x );
301+
</pre>
302+
</div>
220303

221304
<!--
222305
████ ██ ██ ███ ██████ ████████ ███ ███

0 commit comments

Comments
 (0)