class Picture extends Element (View source)

Properties

protected string $element

Default element.

protected bool $isSelfClosing

Whether the element is self closing.

protected string $defaultChild

Default element for nested children.

Methods

__construct(array $sources = array(), $fallbackSrc, $attributes = array(), $lazyLoadNative = false, $lazyLoadJavaScript = false)

No description

static Picture
create(array $sources = array(), string|null $fallbackSrc = false, array $attributes = array(), bool|null $lazyLoadNative = false, bool|null $lazyLoadJavaScript = false)

Static alias for constructor.

sources(array $sources, bool $lazyLoadJavaScript = false)

Create the source elements for the picture element.

noscriptFallback(string $src, bool $lazyLoadNative = false)

Create an img element wrapped in "". The image will be displayed if JavaScript is disabled.

fallback(string $src, bool $lazyLoadNative = false, bool $lazyLoadJavaScript = false)

Create the img element fallback for the picture element.

alt(string $alt)

Set the image fallback and noscript image fallback "alt" attribute value.

title(string $title)

Set the image fallback and noscript image fallback "title" attribute value.

addClass(string $classes)

Add one or more CSS classes to the image and noscript image fallback.

Details

__construct(array $sources = array(), $fallbackSrc, $attributes = array(), $lazyLoadNative = false, $lazyLoadJavaScript = false)

No description

Parameters

array $sources
$fallbackSrc
$attributes
$lazyLoadNative
$lazyLoadJavaScript

static Picture create(array $sources = array(), string|null $fallbackSrc = false, array $attributes = array(), bool|null $lazyLoadNative = false, bool|null $lazyLoadJavaScript = false)

Static alias for constructor.

Parameters

array $sources
string|null $fallbackSrc
array $attributes
bool|null $lazyLoadNative
bool|null $lazyLoadJavaScript

Return Value

Picture

Picture sources(array $sources, bool $lazyLoadJavaScript = false)

Create the source elements for the picture element.

Example output:

or

Parameters

array $sources

An array of image thumbnail file paths.

bool $lazyLoadJavaScript

If true, the source image thumbnail file path is set to a "data-srcset" attribute instead of "srcset".

Return Value

Picture

Picture noscriptFallback(string $src, bool $lazyLoadNative = false)

Create an img element wrapped in "". The image will be displayed if JavaScript is disabled.

Example output:

or

Parameters

string $src

The file path of an image.

bool $lazyLoadNative

If true, the image "loading" attribute is set to "lazy".

Return Value

Picture

fallback(string $src, bool $lazyLoadNative = false, bool $lazyLoadJavaScript = false)

Create the img element fallback for the picture element.

Example output:

or

or

or

Parameters

string $src

The file path of an image.

bool $lazyLoadNative

If true, the image "loading" attribute is set to "lazy".

bool $lazyLoadJavaScript

If true, the image path is set to a "data-src" attribute.

alt(string $alt)

Set the image fallback and noscript image fallback "alt" attribute value.

Parameters

string $alt

title(string $title)

Set the image fallback and noscript image fallback "title" attribute value.

Parameters

string $title

addClass(string $classes)

Add one or more CSS classes to the image and noscript image fallback.

Parameters

string $classes

A string of space separated CSS classes.