SrcsetAttribute

FinalYes

Generates a HTML srcset attribute for responsive images

Table of Contents

Methods

__toString()  : mixed
addCandidate()  : static
createFromDescriptors()  : SrcsetAttribute
generateSrcset()  : string
getCandidates()  : array<string|int, SrcsetCandidate>

Methods

createFromDescriptors()

public static createFromDescriptors(array<string|int, string> $descriptors[, int|null $referenceWidth = null ]) : SrcsetAttribute
Parameters
$descriptors : array<string|int, string>

Array of srcset width (like "300w, 500w") or density (like "1x, 2x") descriptors.

$referenceWidth : int|null = null

Needs to be provided if $descriptors contains density descriptors (like "2x") to be able to resolve the relative image dimensions. The absolute $referenceWidth will be used as "1x" width.

Return values
SrcsetAttribute

generateSrcset()

public generateSrcset() : string
Return values
string

        
On this page

Search results