Cecil

Image

Image Asset class.

Provides methods to manipulate images, such as resizing, cropping, converting, and generating data URLs.

This class uses the Intervention Image library to handle image processing. It supports both GD and Imagick drivers, depending on the available PHP extensions.

Table of Contents

Methods

buildHtmlSrcset()  : string
Build the `srcset` HTML 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.
getHtmlSizes()  : string
Returns the value from the `$sizes` array if the class exists, otherwise returns the default size.
getLqip()  : string
Returns a Low Quality Image Placeholder (LQIP) as data URL.
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.
maskable()  : string
Makes an image Asset maskable, meaning it can be used as a PWA icon.
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

buildHtmlSrcset()

Build the `srcset` HTML attribute for responsive images.

public static buildHtmlSrcset(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, int $quality) : string
Parameters
$asset : Asset
$width : int
$height : int
$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

getHtmlSizes()

Returns the value from the `$sizes` array if the class exists, otherwise returns the default size.

public static getHtmlSizes(string $class[, array<string|int, mixed> $sizes = [] ]) : string
Parameters
$class : string
$sizes : array<string|int, mixed> = []
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

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

maskable()

Makes an image Asset maskable, meaning it can be used as a PWA icon.

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

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