This document defines the concept of an "image resource" and a corresponding WebIDL {{ImageResource}} dictionary. Web APIs can use the {{ImageResource}} dictionary to represent an image resource in contexts where an `HTMLImageElement` is not suitable or available (e.g., in a Worker).
This specification is not stable. Implementors who are not taking part in the discussions will find the specification changing out from under them in incompatible ways.
Web applications often accept developer-provided image resources to be displayed outside of a HTML document (e.g., in the OS, in the browser UI, etc.). This specification defines a WebIDL dictionary that describes an image, and where that image resource can be fetched from. The user agent can then use this extra information to choose an image that is best suited to display on the end-user's device or most closely matches the end-user's preferences or environment.
[=Fetching an image resource=] can reveal the user's IP address. It is RECOMMENDED that user agents fetch the chosen [=image resources=] when provided by the developer, and store them for re-use if needed. This limits tracking the user's location over time.
An image resource consists of:
In an API, an [=image resource=] is represented as an {{ImageResource}} dictionary.
In [[JSON]], [=image resource=] is represented as an object.
dictionary ImageResource { required USVString src; DOMString sizes; DOMString type; DOMString label; };
The {{ImageResource/src}} of an {{ImageResource}} is a [=URL=] from which a user agent can [=fetch=] image data.
The {{ImageResource/sizes}} member is equivalent to a [^link^] element's [^link/sizes^] attribute, and is processed in the same manner.
When multiple {{ImageResource}} dictionaries are available, a user agent MAY use the {{ImageResource/sizes}} value to decide which image is most suitable for a display context (and ignore any that are inappropriate).
const image = { src: "path/to/image.ico", sizes: "16x16 32x32 64x64", type: "image/vnd.microsoft.icon", }; some.api.doSomething(image);
The {{ImageResource/type}} member represents an [=image MIME Type=] for the image resource. A user agent MAY ignore media types it does not support.
There is no default [=MIME type=] for an {{ImageResource}}. The {{ImageResource/type}} is purely advisory. User agents MUST use the [=rules for sniffing images specifically=] to determine the [=computed MIME type=] of an [=image resource=].
The {{ImageResource/label}} of an {{ImageResource}} is a [=string=] that provides the accessible name for the associated image.
Implementors MUST [=derive the accessible name=] for every {{ImageResource}} they expose to users.
Authors are strongly encouraged to add a {{ImageResource/label}} unless the {{ImageResource}}’s [=accessible name=] can be inferred from an external label in its context. For example, in the context of a [=manifest=], the [=manifest/`name`=] (or [=manifest/`short_name`=]) provides an [=external label=] for all members of the [=manifest/`icons`=] array that don’t have a {{ImageResource/label}} defined.
If neither an explicit {{ImageResource/label}} nor an [=external label=] is provided, but the {{ImageResource/type}} supports providing an [=embedded accessible name=], implementors MAY choose to defer assigning the {{ImageResource/label}} until the {{ImageResource/src}} has been fetched and processed. If the {{ImageResource/src}} is found to provide an [=embedded accessible name=], implementors MUST update the {{ImageResource/label}} to match that value.
The steps to process an `ImageResource` from an API are given by the following algorithm. The algorithm takes an {{ImageResource}} |input:ImageResource|. It returns an [=image resource=].
To process an image resource from JSON, given a JSON Object |input:object| and a [=URL=] |base:URL|. It returns an [=ordered map=].
The steps for fetching an image resource are given by the following algorithm. The algorithm takes an [=image resource=] |image|, and an optional [=Request=] |request|. It returns a [=Response=].
The steps to derive the accessible name for an [=image resource=] |resource| are as follows. It returns a [=string=].
Certain graphics formats support the inclusion of an embedded accessible name as part of the image’s contents. Examples include: