Image
Image class. Provides methods to manipulate images, such as resizing, cropping, converting, and generating data URLs.
Table of Contents
Methods
- buildSrcset() : string
- Build the `srcset` attribute for responsive images.
- convert() : string
- Converts an image Asset to the target format.
- cover() : string
- Crops an image Asset to the given width and height, keeping the aspect ratio.
- getDataUrl() : string
- Returns the Data URL (encoded in Base64).
- getDominantColor() : string
- Returns the dominant RGB color of an image asset.
- getLqip() : string
- Returns a Low Quality Image Placeholder (LQIP) as data URL.
- getSizes() : string
- Returns the value of the "sizes" attribute corresponding to the configured class.
- getSvgAttributes() : SimpleXMLElement|false
- Returns SVG attributes.
- isAnimatedGif() : bool
- Checks if an asset is an animated GIF.
- isIco() : bool
- Returns true if asset is an ICO.
- isImage() : bool
- Asset is a valid image?
- isSVG() : bool
- Returns true if asset is a SVG.
- resize() : string
- Scales down an image Asset to the given width, keeping the aspect ratio.
- manager() : ImageManager
- Create new manager instance with available driver.
Methods
buildSrcset()
Build the `srcset` attribute for responsive images.
public
static buildSrcset(Asset $asset, array<string|int, mixed> $widths) : string
e.g.: srcset="/img-480.jpg 480w, /img-800.jpg 800w"
.
Parameters
- $asset : Asset
- $widths : array<string|int, mixed>
Tags
Return values
stringconvert()
Converts an image Asset to the target format.
public
static convert(Asset $asset, string $format, int $quality) : string
Parameters
- $asset : Asset
- $format : string
- $quality : int
Tags
Return values
stringcover()
Crops an image Asset to the given width and height, keeping the aspect ratio.
public
static cover(Asset $asset, int $width, int $height, string $position, int $quality) : string
Parameters
- $asset : Asset
- $width : int
- $height : int
- $position : string
- $quality : int
Tags
Return values
stringgetDataUrl()
Returns the Data URL (encoded in Base64).
public
static getDataUrl(Asset $asset, int $quality) : string
Parameters
- $asset : Asset
- $quality : int
Tags
Return values
stringgetDominantColor()
Returns the dominant RGB color of an image asset.
public
static getDominantColor(Asset $asset) : string
Parameters
- $asset : Asset
Tags
Return values
stringgetLqip()
Returns a Low Quality Image Placeholder (LQIP) as data URL.
public
static getLqip(Asset $asset) : string
Parameters
- $asset : Asset
Tags
Return values
stringgetSizes()
Returns the value of the "sizes" attribute corresponding to the configured class.
public
static getSizes(string $class[, array<string|int, mixed> $sizes = [] ]) : string
Parameters
- $class : string
- $sizes : array<string|int, mixed> = []
Return values
stringgetSvgAttributes()
Returns SVG attributes.
public
static getSvgAttributes(Asset $asset) : SimpleXMLElement|false
Parameters
- $asset : Asset
Return values
SimpleXMLElement|falseisAnimatedGif()
Checks if an asset is an animated GIF.
public
static isAnimatedGif(Asset $asset) : bool
Parameters
- $asset : Asset
Return values
boolisIco()
Returns true if asset is an ICO.
public
static isIco(Asset $asset) : bool
Parameters
- $asset : Asset
Return values
boolisImage()
Asset is a valid image?
public
static isImage(Asset $asset) : bool
Parameters
- $asset : Asset
Return values
boolisSVG()
Returns true if asset is a SVG.
public
static isSVG(Asset $asset) : bool
Parameters
- $asset : Asset
Return values
boolresize()
Scales down an image Asset to the given width, keeping the aspect ratio.
public
static resize(Asset $asset, int $width, int $quality) : string
Parameters
- $asset : Asset
- $width : int
- $quality : int
Tags
Return values
stringmanager()
Create new manager instance with available driver.
private
static manager() : ImageManager