WidthSrcsetCandidate extends SrcsetCandidate

FinalYes

Represents a source candidate for the HTML srcset attribute using the "w" unit (absolute width in image pixels, like "200w")

Table of Contents

Constants

DENSITY_UNIT  = 'x'
WIDTH_UNIT  = 'w'

Properties

$uri  : string|null
$width  : int

Methods

__construct()  : mixed
__toString()  : mixed
createFromDescriptor()  : SrcsetCandidate
generateSrcset()  : string
getCalculatedWidth()  : int
getDescriptor()  : string
getSanitizedUri()  : string|null
Ensures that the provided URI can be used safely in a srcset attribute
getUri()  : string|null
setUri()  : static
setWidth()  : static

Constants

DENSITY_UNIT

public mixed DENSITY_UNIT = 'x'

Properties

Methods

__construct()

public __construct(int $width) : mixed
Parameters
$width : int

createFromDescriptor()

public static createFromDescriptor(string $descriptor[, int|null $referenceWidth = null ]) : SrcsetCandidate
Parameters
$descriptor : string

srcset width (like "300w") or density (like "2x") descriptor.

$referenceWidth : int|null = null

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

Return values
SrcsetCandidate

generateSrcset()

public generateSrcset() : string
Return values
string

getCalculatedWidth()

public getCalculatedWidth() : int
Return values
int

getDescriptor()

public getDescriptor() : string
Return values
string

getSanitizedUri()

Ensures that the provided URI can be used safely in a srcset attribute

public getSanitizedUri() : string|null
Return values
string|null

getUri()

public getUri() : string|null
Return values
string|null

setUri()

public setUri(string $uri) : static
Parameters
$uri : string
Return values
static

setWidth()

public setWidth(int $width) : static
Parameters
$width : int
Return values
static

        
On this page

Search results