class ImageOptions

ImageOptions allows specifying extended options to the Contentful Image API .

to resize images or change their format.

Methods

__construct()

ImageOptions constructor.

string
getQueryString()

The urlencoded query string for these options.

int|null
getWidth()

Get the width of the image. Will be null if no width is set.

$this
setWidth(int|null $width = null)

Set the width of the image.

int|null
getHeight()

Get the height of the image. Will be null if no height is set.

$this
setHeight(int|null $height = null)

Set the height of the image.

string|null
getFormat()

Format of the image. Possible values are "png" and "jpg". Will be null if no format is set.

$this
setFormat(string|null $format = null)

Set the format of the image. Valid values are "png" and "jpg". Can be set to null to not enforce a format.

int|null
getQuality()

Quality of the JPEG encoded image. Will be null if no quality is set.

$this
setQuality(int|null $quality = null)

Quality of the JPEG encoded image.

bool
isProgressive()

Returns true if the image will be loaded as progressive JPEG.

$this
setProgressive(bool|null $progressive = null)

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

null|string
getResizeFit()

Returns the behavior used for resizing images.

$this
setResizeFit(string|null $resizeFit = null)

Change the behavior when resizing the image.

string|null
getResizeFocus()

Get the focus area for resizing.

$this
setResizeFocus(string|null $resizeFocus = null)

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

float|null
getRadius()

Radius used to crop the image.

$this
setRadius(float|null $radius = null)

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

string|null
getBackgroundColor()

Returns the background color used when padding an image.

$this
setBackgroundColor(string|null $backgroundColor = null)

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

Details

at line 71
__construct()

ImageOptions constructor.

Empty, only included for forward compatibility.

at line 82
string getQueryString()

The urlencoded query string for these options.

Return Value

string

at line 119
int|null getWidth()

Get the width of the image. Will be null if no width is set.

Return Value

int|null

at line 140
$this setWidth(int|null $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|null $width The width in pixel.

Return Value

$this

Exceptions

InvalidArgumentException If $width is negative

at line 158
int|null getHeight()

Get the height of the image. Will be null if no height is set.

Return Value

int|null

at line 179
$this setHeight(int|null $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|null $height The height in pixel.

Return Value

$this

Exceptions

InvalidArgumentException If $height is negative

at line 197
string|null getFormat()

Format of the image. Possible values are "png" and "jpg". Will be null if no format is set.

Return Value

string|null

at line 217
$this setFormat(string|null $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|null $format

Return Value

$this

Exceptions

InvalidArgumentException If $format is not a valid value

at line 237
int|null getQuality()

Quality of the JPEG encoded image. Will be null if no quality is set.

Return Value

int|null If an int, must be between 1 and 100.

at line 255
$this setQuality(int|null $quality = null)

Quality of the JPEG encoded image.

The image format will be forced to JPEG.

Parameters

int|null $quality If an int, between 1 and 100.

Return Value

$this

Exceptions

InvalidArgumentException If $quality is out of range

at line 273
bool isProgressive()

Returns true if the image will be loaded as progressive JPEG.

Return Value

bool

at line 289
$this setProgressive(bool|null $progressive = null)

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

The image format will be forced to JPEG.

Parameters

bool|null $progressive

Return Value

$this

at line 303
null|string getResizeFit()

Returns the behavior used for resizing images.

Return Value

null|string

at line 330
$this setResizeFit(string|null $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|null $resizeFit

Return Value

$this

Exceptions

InvalidArgumentException For unknown values of $resizeBehavior

at line 350
string|null getResizeFocus()

Get the focus area for resizing.

Return Value

string|null

at line 371
$this setResizeFocus(string|null $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|null $resizeFocus

Return Value

$this

Exceptions

InvalidArgumentException For unknown values of $resizeFocus

at line 391
float|null getRadius()

Radius used to crop the image.

Return Value

float|null

at line 407
$this setRadius(float|null $radius = null)

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

Parameters

float|null $radius A float value defining the corner radius.

Return Value

$this

Exceptions

InvalidArgumentException If $radius is negative

at line 425
string|null getBackgroundColor()

Returns the background color used when padding an image.

Return Value

string|null

at line 443
$this setBackgroundColor(string|null $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|null $backgroundColor

Return Value

$this

Exceptions

InvalidArgumentException If the $backgroundColor is not in hexadecimal format.