DensitySrcsetCandidate extends SrcsetCandidate
FinalYes
Represents a source candidate for the HTML srcset attribute using the "x" unit (relative pixel density, like "1x" or "2x")
Table of Contents
Constants
- DENSITY_UNIT = 'x'
- WIDTH_UNIT = 'w'
Properties
- $density : float
- $referenceWidth : int|null
- $uri : string|null
Methods
- __construct() : mixed
- __toString() : mixed
- createFromDescriptor() : SrcsetCandidate
- generateSrcset() : string
- getCalculatedWidth() : int
- getDensity() : float
- getDescriptor() : string
- getReferenceWidth() : int|null
- getSanitizedUri() : string|null
- Ensures that the provided URI can be used safely in a srcset attribute
- getUri() : string|null
- setDensity() : static
- setReferenceWidth() : static
- The absolute $referenceWidth will be used as "1x" width.
- setUri() : static
Constants
DENSITY_UNIT
public
mixed
DENSITY_UNIT
= 'x'
WIDTH_UNIT
public
mixed
WIDTH_UNIT
= 'w'
Properties
$density
protected
float
$density
$referenceWidth
protected
int|null
$referenceWidth
= null
$uri
protected
string|null
$uri
= null
Methods
__construct()
public
__construct(float $density[, int|null $referenceWidth = null ]) : mixed
Parameters
- $density : float
- $referenceWidth : int|null = null
__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
intgetDensity()
public
getDensity() : float
Return values
floatgetDescriptor()
public
getDescriptor() : string
Return values
stringgetReferenceWidth()
public
getReferenceWidth() : int|null
Return values
int|nullgetSanitizedUri()
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|nullsetDensity()
public
setDensity(float $density) : static
Parameters
- $density : float
Return values
staticsetReferenceWidth()
The absolute $referenceWidth will be used as "1x" width.
public
setReferenceWidth(int $referenceWidth) : static
Parameters
- $referenceWidth : int
Return values
staticsetUri()
public
setUri(string $uri) : static
Parameters
- $uri : string