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 = [], $fallbackSrc = '', $attributes = [], $lazyLoadNative = false, $lazyLoadJavaScript = false)

No description

static Picture
create(array $sources = [], string|null $fallbackSrc = false, array $attributes = [], 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.

setAttribute(string $attribute, string|null $value = null)

Set an attribute.

Details

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

No description

Parameters

array $sources
$fallbackSrc
$attributes
$lazyLoadNative
$lazyLoadJavaScript

static Picture create(array $sources = [], string|null $fallbackSrc = false, array $attributes = [], 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

setAttribute(string $attribute, string|null $value = null)

Set an attribute.

Parameters

string $attribute
string|null $value