Cecil

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
throws
RuntimeException
Return values
string

convert()

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
throws
RuntimeException
Return values
string

cover()

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
throws
RuntimeException
Return values
string

getDataUrl()

Returns the Data URL (encoded in Base64).

public static getDataUrl(Asset $asset, int $quality) : string
Parameters
$asset : Asset
$quality : int
Tags
throws
RuntimeException
Return values
string

getDominantColor()

Returns the dominant RGB color of an image asset.

public static getDominantColor(Asset $asset) : string
Parameters
$asset : Asset
Tags
throws
RuntimeException
Return values
string

getLqip()

Returns a Low Quality Image Placeholder (LQIP) as data URL.

public static getLqip(Asset $asset) : string
Parameters
$asset : Asset
Tags
throws
RuntimeException
Return values
string

getSizes()

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
string

getSvgAttributes()

Returns SVG attributes.

public static getSvgAttributes(Asset $asset) : SimpleXMLElement|false
Parameters
$asset : Asset
Return values
SimpleXMLElement|false

isAnimatedGif()

Checks if an asset is an animated GIF.

public static isAnimatedGif(Asset $asset) : bool
Parameters
$asset : Asset
Return values
bool

isIco()

Returns true if asset is an ICO.

public static isIco(Asset $asset) : bool
Parameters
$asset : Asset
Return values
bool

isImage()

Asset is a valid image?

public static isImage(Asset $asset) : bool
Parameters
$asset : Asset
Return values
bool

isSVG()

Returns true if asset is a SVG.

public static isSVG(Asset $asset) : bool
Parameters
$asset : Asset
Return values
bool

resize()

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
throws
RuntimeException
Return values
string

manager()

Create new manager instance with available driver.

private static manager() : ImageManager
Return values
ImageManager
 
On this page

Search results