class ImageOptions implements UrlOptionsInterface

ImageOptions class.

This class allows specifying extended options to the Contentful Image API, to resize images or change their format.

Methods

getQueryString()

The urlencoded query string for these options.

$this
setWidth(int $width = null)

Set the width of the image.

$this
setHeight(int $height = null)

Set the height of the image.

$this
setFormat(string $format = null)

Set the format of the image. Valid values are "png" and "jpg".

$this
setQuality(int $quality = null)

Quality of the JPEG encoded image.

$this
setProgressive(bool $progressive)

Set to true to load the image as a progressive JPEG.

$this
setPng8Bit(bool $png8Bit)

Set to true to load the image as a 8-bit PNG.

$this
setResizeFit(string $resizeFit = null)

Change the behavior when resizing the image.

$this
setResizeFocus(string $resizeFocus = null)

Set the focus area when the resize fit is set to 'thumb'.

$this
setRadius(float $radius = null)

Add rounded corners to your image or crop to a circle/ellipsis.

$this
setBackgroundColor(string $backgroundColor = null)

Background color, relevant if the resize fit type 'pad' is used.

Details

at line 77
getQueryString()

The urlencoded query string for these options.

at line 132
$this setWidth(int $width = null)

Set the width of the image.

The image will by default not be stretched, skewed or enlarged. Instead it will be fit into the bounding box given by the width and height parameters.

Can be set to null to not set a width.

Parameters

int $width the width in pixel

Return Value

$this

Exceptions

InvalidArgumentException If $width is negative

at line 158
$this setHeight(int $height = null)

Set the height of the image.

The image will by default not be stretched, skewed or enlarged. Instead it will be fit into the bounding box given by the width and height parameters.

Can be set to null to not set a height.

Parameters

int $height the height in pixel

Return Value

$this

Exceptions

InvalidArgumentException If $height is negative

at line 177
$this setFormat(string $format = null)

Set the format of the image. Valid values are "png" and "jpg".

Can be set to null to not enforce a format.

Parameters

string $format

Return Value

$this

Exceptions

InvalidArgumentException If $format is not a valid value

at line 200
$this setQuality(int $quality = null)

Quality of the JPEG encoded image.

The image format will be forced to JPEG.

Parameters

int $quality if an int, between 1 and 100

Return Value

$this

Exceptions

InvalidArgumentException If $quality is out of range

at line 217
$this setProgressive(bool $progressive)

Set to true to load the image as a progressive JPEG.

The image format will be forced to JPEG.

Parameters

bool $progressive

Return Value

$this

at line 230
$this setPng8Bit(bool $png8Bit)

Set to true to load the image as a 8-bit PNG.

The image format will be forced to PNG.

Parameters

bool $png8Bit

Return Value

$this

at line 255
$this setResizeFit(string $resizeFit = null)

Change the behavior when resizing the image.

By default, images are resized to fit inside the bounding box set trough setWidth and setHeight while retaining their aspect ratio.

Possible values are: - null for the default value - 'pad' Same as the default, but add padding so that the generated image has exactly the given dimensions. - 'crop' Crop a part of the original image. - 'fill' Fill the given dimensions by cropping the image. - 'thumb' Create a thumbnail of detected faces from image, used with 'setFocus'. - 'scale' Scale the image regardless of the original aspect ratio.

Parameters

string $resizeFit

Return Value

$this

Exceptions

InvalidArgumentException For unknown values of $resizeBehavior

at line 280
$this setResizeFocus(string $resizeFocus = null)

Set the focus area when the resize fit is set to 'thumb'.

Possible values are: - 'top', 'right', 'left', 'bottom' - A combination like 'bottom_right' - 'face' or 'faces' to focus the resizing via face detection

Parameters

string $resizeFocus

Return Value

$this

Exceptions

InvalidArgumentException For unknown values of $resizeFocus

at line 314
$this setRadius(float $radius = null)

Add rounded corners to your image or crop to a circle/ellipsis.

Parameters

float $radius a float value defining the corner radius

Return Value

$this

Exceptions

InvalidArgumentException If $radius is negative

at line 333
$this setBackgroundColor(string $backgroundColor = null)

Background color, relevant if the resize fit type 'pad' is used.

Expects a valid hexadecimal HTML color like '#9090ff'. Default is transparency.

Parameters

string $backgroundColor

Return Value

$this

Exceptions

InvalidArgumentException if the $backgroundColor is not in hexadecimal format