pub struct ImgBuilder(/* private fields */);Implementations§
Source§impl ImgBuilder
impl ImgBuilder
pub fn id(self, value: impl AttributeValue<String>) -> Self
pub fn class(self, value: impl AttributeValue<String>) -> Self
Sourcepub fn alt(self, value: impl AttributeValue<String>) -> Self
pub fn alt(self, value: impl AttributeValue<String>) -> Self
Defines an alternative text description of the image.
Note: Browsers do not always display images. For example:
- Non-visual browsers (such as those used by people with visual impairments)
- The user chooses not to display images (saving bandwidth, privacy reasons)
- The image is invalid or an unsupported type
- In these cases, the browser may replace the image with the text in the element’s alt attribute. For these reasons and others, provide a useful value for alt whenever possible.
Omitting alt altogether indicates that the image is a key part of the content and no textual equivalent is available. Setting this attribute to an empty string (alt=“”) indicates that this image is not a key part of the content (it’s decoration or a tracking pixel), and that non-visual browsers may omit it from rendering. Visual browsers will also hide the broken image icon if the alt is empty and the image failed to display.
This attribute is also used when copying and pasting the image to text, or saving a linked image to a bookmark.
Sourcepub fn crossorigin(self, value: impl AttributeValue<String>) -> Self
pub fn crossorigin(self, value: impl AttributeValue<String>) -> Self
Indicates if the fetching of the image must be done using a CORS request. Image data
from a CORS-enabled image returned from a CORS request can be reused in the <canvas>
element without being marked “tainted”.
If the crossorigin attribute is not specified, then a non-CORS request is sent (without
the Origin request header), and the browser marks the image as tainted and restricts
access to its image data, preventing its usage in <canvas> elements.
If the crossorigin attribute is specified, then a CORS request is sent (with the Origin
request header); but if the server does not opt into allowing cross-origin access to the
image data by the origin site (by not sending any Access-Control-Allow-Origin response
header, or by not including the site’s origin in any Access-Control-Allow-Origin
response header it does send), then the browser marks the image as tainted and restricts
access to its image data, preventing its usage in <canvas> elements.
Allowed values:
anonymous: A CORS request is sent with credentials omitted (that is, no cookies, X.509 certificates, or Authorization request header).use-credentials: The CORS request is sent with any credentials included (that is, cookies, X.509 certificates, and theAuthorizationrequest header). If the server does not opt into sharing credentials with the origin site (by sending back theAccess-Control-Allow-Credentials: trueresponse header), then the browser marks the image as tainted and restricts access to its image data.
If the attribute has an invalid value, browsers handle it as if the anonymous value was used.
Sourcepub fn decoding(self, value: impl AttributeValue<String>) -> Self
pub fn decoding(self, value: impl AttributeValue<String>) -> Self
Provides an image decoding hint to the browser. Allowed values:
sync: Decode the image synchronously, for atomic presentation with other content.async: Decode the image asynchronously, to reduce delay in presenting other content.auto: Default: no preference for the decoding mode. The browser decides what is best for the user.
Sourcepub fn height(self, value: impl AttributeValue<String>) -> Self
pub fn height(self, value: impl AttributeValue<String>) -> Self
The intrinsic height of the image, in pixels. Must be an integer without a unit.
Sourcepub fn ismap(self, value: impl AttributeValue<bool>) -> Self
pub fn ismap(self, value: impl AttributeValue<bool>) -> Self
Indicates that the image is part of a server-side map. If so, the coordinates where the user clicked on the image are sent to the server.
Note: This attribute is allowed only if the <img> element is a descendant of an <a>
element with a valid href attribute. This gives users without pointing devices a
fallback destination.
Sourcepub fn loading(self, value: impl AttributeValue<String>) -> Self
pub fn loading(self, value: impl AttributeValue<String>) -> Self
Indicates how the browser should load the image:
eager: Loads the image immediately, regardless of whether or not the image is currently within the visible viewport (this is the default value).lazy: Defers loading the image until it reaches a calculated distance from the viewport, as defined by the browser. The intent is to avoid the network and storage bandwidth needed to handle the image until it’s reasonably certain that it will be needed. This generally improves the performance of the content in most typical use cases.
Note: Loading is only deferred when JavaScript is enabled. This is an anti-tracking measure, because if a user agent supported lazy loading when scripting is disabled, it would still be possible for a site to track a user’s approximate scroll position throughout a session, by strategically placing images in a page’s markup such that a server can track how many images are requested and when.
Sourcepub fn sizes(self, value: impl AttributeValue<String>) -> Self
pub fn sizes(self, value: impl AttributeValue<String>) -> Self
One or more strings separated by commas, indicating a set of source sizes. Each source size consists of:
- A media condition. This must be omitted for the last item in the list.
- A source size value.
Media Conditions describe properties of the viewport, not of the image. For example, (max-height: 500px) 1000px proposes to use a source of 1000px width, if the viewport is not higher than 500px.
Source size values specify the intended display size of the image. User agents use the current source size to select one of the sources supplied by the srcset attribute, when those sources are described using width (w) descriptors. The selected source size affects the intrinsic size of the image (the image’s display size if no CSS styling is applied). If the srcset attribute is absent, or contains no values with a width descriptor, then the sizes attribute has no effect.
Sourcepub fn src(self, value: impl AttributeValue<String>) -> Self
pub fn src(self, value: impl AttributeValue<String>) -> Self
The image URL. Mandatory for the <img> element. On browsers supporting srcset, src is
treated like a candidate image with a pixel density descriptor 1x, unless an image with
this pixel density descriptor is already defined in srcset, or unless srcset contains w
descriptors.
Sourcepub fn srcset(self, value: impl AttributeValue<String>) -> Self
pub fn srcset(self, value: impl AttributeValue<String>) -> Self
One or more strings separated by commas, indicating possible image sources for the user agent to use. Each string is composed of:
- A URL to an image
- Optionally, whitespace followed by one of:
- A width descriptor (a positive integer directly followed by w). The width descriptor is divided by the source size given in the sizes attribute to calculate the effective pixel density.
- A pixel density descriptor (a positive floating point number directly followed by x).
- If no descriptor is specified, the source is assigned the default descriptor of 1x.
It is incorrect to mix width descriptors and pixel density descriptors in the same srcset attribute. Duplicate descriptors (for instance, two sources in the same srcset which are both described with 2x) are also invalid.
The user agent selects any of the available sources at its discretion. This provides them with significant leeway to tailor their selection based on things like user preferences or bandwidth conditions. See our Responsive images tutorial for an example.
Sourcepub fn width(self, value: impl AttributeValue<String>) -> Self
pub fn width(self, value: impl AttributeValue<String>) -> Self
The intrinsic width of the image in pixels. Must be an integer without a unit.
Sourcepub fn usemap(self, value: impl AttributeValue<String>) -> Self
pub fn usemap(self, value: impl AttributeValue<String>) -> Self
The partial URL (starting with #) of an image map associated with the element.
Note: You cannot use this attribute if the <img> element is inside an <a> or
<button> element.