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 73
__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 117
int|null getWidth()

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

Return Value

int|null

at line 136
$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 152
int|null getHeight()

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

Return Value

int|null

at line 171
$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 187
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 205
$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 223
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 239
$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 255
bool isProgressive()

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

Return Value

bool

at line 269
$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 281
null|string getResizeFit()

Returns the behavior used for resizing images.

Return Value

null|string

at line 306
$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 324
string|null getResizeFocus()

Get the focus area for resizing.

Return Value

string|null

at line 343
$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 361
float|null getRadius()

Radius used to crop the image.

Return Value

float|null

at line 375
$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 391
string|null getBackgroundColor()

Returns the background color used when padding an image.

Return Value

string|null

at line 407
$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