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
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'
WIDTH_UNIT
public
mixed
WIDTH_UNIT
= 'w'
Properties
$uri
protected
string|null
$uri
= null
$width
protected
int
$width
Methods
__construct()
public
__construct(int $width) : mixed
Parameters
- $width : int
__toString()
public
__toString() : mixed
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
SrcsetCandidategenerateSrcset()
public
generateSrcset() : string
Return values
stringgetCalculatedWidth()
public
getCalculatedWidth() : int
Return values
intgetDescriptor()
public
getDescriptor() : string
Return values
stringgetSanitizedUri()
Ensures that the provided URI can be used safely in a srcset attribute
public
getSanitizedUri() : string|null
Return values
string|nullgetUri()
public
getUri() : string|null
Return values
string|nullsetUri()
public
setUri(string $uri) : static
Parameters
- $uri : string
Return values
staticsetWidth()
public
setWidth(int $width) : static
Parameters
- $width : int