@@ -19,6 +19,7 @@ Previous Version: https://www.w3.org/TR/2012/WD-css4-images-20120911/
19
19
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
20
20
Ignored Vars : H, P
21
21
Include Can I Use Panels : yes
22
+ Default Highlight : css
22
23
</pre>
23
24
24
25
<pre class=link-defaults>
@@ -149,7 +150,7 @@ Note: No change from [[css3-images]].
149
150
-->
150
151
151
152
152
- Resolution Negotiation: the ''image-set()'' notation {#image-set-notation}
153
+ Resolution/Type Negotiation: the ''image-set()'' notation {#image-set-notation}
153
154
--------------------------------------------------------------------------
154
155
155
156
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}
174
175
175
176
<pre class='prod'>
176
177
<dfn caniuse="css-image-set">image-set()</dfn> = image-set( <<image-set-option>> # )
177
- <dfn><image-set-option></dfn> = [ <<image>> | <<string>> ] <<resolution>>
178
+ <dfn><image-set-option></dfn> = [ <<image>> | <<string>> ]
179
+ [ <<resolution>> || type(<<string>> ) ]
178
180
</pre>
179
181
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
181
183
to match the functionality of HTML's <a element>picture</a> .
182
184
185
+ Each <<string>> inside ''image-set()'' represents a <<url>> .
186
+
183
187
The ''image-set()'' function can not be nested inside of itself,
184
188
either directly
185
189
or indirectly
186
190
(as an argument to another <<image>> type).
187
191
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>> .
194
247
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.
202
248
UAs <strong> may</strong> change which <<image-set-option>> they wish to use for a given ''image-set()''
203
249
over the lifetime of the page,
204
250
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}
217
263
</pre>
218
264
</div>
219
265
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>
220
303
221
304
<!--
222
305
████ ██ ██ ███ ██████ ████████ ███ ███
0 commit comments