trait ResizeTrait

Trait ImageResizeTrait

Methods

generic(string $resizeName, int|float|string|null $width = null, int|float|null $height = null)

Generic resize builder.

scale(int|float|string|null $width = null, int|float|null $height = null, int|float|array $aspectRatio = null)

Change the size of the image exactly to the given width and height without necessarily retaining the original aspect ratio: all original image parts are visible but might be stretched or shrunk.

fit(int|float|string|null $width = null, int|float|null $height = null, int|float|array $aspectRatio = null)

The image is resized so that it takes up as much space as possible within a bounding box defined by the given width and height qualifiers. The original aspect ratio is retained and all of the original image is visible.

limitFit(int|float|string $width = null, int|float $height = null, int|float|array $aspectRatio = null)

Same as the Scale::fit mode but only if the original image is larger than the given limit (width and height), in which case the image is scaled down so that it takes up as much space as possible within a bounding box defined by the given width and height qualifiers. The original aspect ratio is retained and all of the original image is visible.

minimumFit(int|float|string|null $width = null, int|float|null $height = null, int|float|array $aspectRatio = null)

Same as the Scale::fit mode but only if the original image is smaller than the given minimum (width and height), in which case the image is scaled up so that it takes up as much space as possible within a bounding box defined by the given width and height qualifiers. The original aspect ratio is retained and all of the original image is visible.

gravity(string $compassGravity)

Sets the compass direction.

offsetX(int|float|string $x)

Sets the x offset.

offsetY(int|float|string $y)

Sets the y offset.

offset(int|float|string $x = null, int|float|string $y = null)

Sets the x and y offset.

background(Background|ColorValue|string $background)

Sets the background.

pad(int|float|string|null $width = null, int|float|null $height = null, string|ColorValue $background = null)

Resizes the image to fill the given width and height while retaining the original aspect ratio and with all of the original image visible.

limitPad(int|float|string|null $width = null, int|float|null $height = null, string|ColorValue $background = null)

Same as the Pad::pad mode but only if the original image is larger than the given limit (width and height), in which case the image is scaled down to fill the given width and height while retaining the original aspect ratio and with all of the original image visible.

minimumPad(int|float|string|null $width = null, int|float|null $height = null, string|ColorValue $background = null)

Same as the Pad::pad mode but only if the original image is smaller than the given minimum (width and height), in which case the image is scaled up to fill the given width and height while retaining the original aspect ratio and with all of the original image visible.

position(BasePosition $position)

Sets pad position.

fill(int|float|string|null $width = null, int|float|null $height = null, Gravity $gravity = null)

Creates an image with the exact given width and height without distorting the image.

limitFill(int|float|string|null $width = null, int|float|null $height = null, Gravity $gravity = null)

Same as the Fill::fill mode, but only if the original image is larger than the specified resolution limits, in which case the image is scaled down to fill the given width and height without distorting the image, and then the dimension that exceeds the request is cropped.

fillPad(int|float|string|null $width = null, int|float|null $height = null, FocalGravity|string $gravity = null, string|ColorValue $background = null)

Tries to prevent a "bad crop" by first attempting to use the fill mode, but adding padding if it is determined that more of the original image needs to be included in the final image.

crop(int|float|string|null $width = null, int|float|null $height = null, Gravity $gravity = null, int|float|X $x = null, int|float|Y $y = null)

Extracts a region of the given width and height out of the original image.

thumbnail(int|float|string|null $width = null, int|float|null $height = null, Gravity $gravity = null, int|float|X $x = null, int|float|Y $y = null)

The thumb cropping mode is specifically used for creating image thumbnails from either face or custom coordinates, and must always be accompanied by the gravity qualifier set to one of the face detection or custom values.

imaggaCrop(int|float|string|null $width = null, int|float|null $height = null)

Generates the best cropped version of the original image using the Imagga add-on.

imaggaScale(int|float|string|null $width = null, int|float|null $height = null)

Generates a smartly scaled image that perfectly fits the requested dimensions.

Details

static GenericResizeTrait generic(string $resizeName, int|float|string|null $width = null, int|float|null $height = null)

Generic resize builder.

Parameters

Name Type Description
$resizeName string Provide future (not supported in the current version) resize name.
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.

Return Value

GenericResizeTrait

static Scale scale(int|float|string|null $width = null, int|float|null $height = null, int|float|array $aspectRatio = null)

Change the size of the image exactly to the given width and height without necessarily retaining the original aspect ratio: all original image parts are visible but might be stretched or shrunk.

Parameters

Name Type Description
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.
$aspectRatio int|float|array Resizes the asset to a new aspect ratio.

Return Value

Scale

static Scale fit(int|float|string|null $width = null, int|float|null $height = null, int|float|array $aspectRatio = null)

The image is resized so that it takes up as much space as possible within a bounding box defined by the given width and height qualifiers. The original aspect ratio is retained and all of the original image is visible.

Parameters

Name Type Description
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.
$aspectRatio int|float|array Resizes the asset to a new aspect ratio.

Return Value

Scale

static Scale limitFit(int|float|string $width = null, int|float $height = null, int|float|array $aspectRatio = null)

Same as the Scale::fit mode but only if the original image is larger than the given limit (width and height), in which case the image is scaled down so that it takes up as much space as possible within a bounding box defined by the given width and height qualifiers. The original aspect ratio is retained and all of the original image is visible.

Parameters

Name Type Description
$width int|float|string The required width of a transformed asset.
$height int|float The required height of a transformed asset.
$aspectRatio int|float|array Resizes the asset to a new aspect ratio.

Return Value

Scale

See also

Scale::fit

static Scale minimumFit(int|float|string|null $width = null, int|float|null $height = null, int|float|array $aspectRatio = null)

Same as the Scale::fit mode but only if the original image is smaller than the given minimum (width and height), in which case the image is scaled up so that it takes up as much space as possible within a bounding box defined by the given width and height qualifiers. The original aspect ratio is retained and all of the original image is visible.

Parameters

Name Type Description
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.
$aspectRatio int|float|array Resizes the asset to a new aspect ratio.

Return Value

Scale

See also

Scale::fit

CompassGravityTrait gravity(string $compassGravity)

Sets the compass direction.

The compass direction represents a location in the image, for example, Gravity::northEast() represents the top right corner.

Parameters

Name Type Description
$compassGravity string

Return Value

CompassGravityTrait

See also

Gravity::northEast

$this offsetX(int|float|string $x)

Sets the x offset.

Parameters

Name Type Description
$x int|float|string The x offset.

Return Value

$this

$this offsetY(int|float|string $y)

Sets the y offset.

Parameters

Name Type Description
$y int|float|string The y offset.

Return Value

$this

OffsetTrait offset(int|float|string $x = null, int|float|string $y = null)

Sets the x and y offset.

Parameters

Name Type Description
$x int|float|string The x offset.
$y int|float|string The y offset.

Return Value

OffsetTrait

$this background(Background|ColorValue|string $background)

Sets the background.

The image background is visible when padding is added with one of the padding crop modes, when rounding corners, when adding overlays, and with semi-transparent PNGs and GIFs.

Parameters

Name Type Description
$background Background|ColorValue|string The the background to set.

Return Value

$this

See also

Background

static Pad pad(int|float|string|null $width = null, int|float|null $height = null, string|ColorValue $background = null)

Resizes the image to fill the given width and height while retaining the original aspect ratio and with all of the original image visible.

If the proportions of the original image do not match the given width and height, padding is added to the image to reach the required size

Parameters

Name Type Description
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.
$background string|ColorValue Sets the background color of the image.

Return Value

Pad

static Pad limitPad(int|float|string|null $width = null, int|float|null $height = null, string|ColorValue $background = null)

Same as the Pad::pad mode but only if the original image is larger than the given limit (width and height), in which case the image is scaled down to fill the given width and height while retaining the original aspect ratio and with all of the original image visible.

This mode doesn't scale up the image if your requested dimensions are bigger than the original image's.

Parameters

Name Type Description
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.
$background string|ColorValue Sets the background color of the image.

Return Value

Pad

See also

Pad::pad

static Pad minimumPad(int|float|string|null $width = null, int|float|null $height = null, string|ColorValue $background = null)

Same as the Pad::pad mode but only if the original image is smaller than the given minimum (width and height), in which case the image is scaled up to fill the given width and height while retaining the original aspect ratio and with all of the original image visible.

This mode doesn't scale down the image if your requested dimensions are smaller than the original image's.

Parameters

Name Type Description
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.
$background string|ColorValue Sets the background color of the image.

Return Value

Pad

See also

Pad::pad

$this position(BasePosition $position)

Sets pad position.

Parameters

Name Type Description
$position BasePosition The desired position

Return Value

$this

static Fill fill(int|float|string|null $width = null, int|float|null $height = null, Gravity $gravity = null)

Creates an image with the exact given width and height without distorting the image.

This option first scales up or down as much as needed to at least fill both of the given dimensions. If the requested aspect ratio is different than the original, cropping will occur on the dimension that exceeds the requested size after scaling.

Parameters

Name Type Description
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.
$gravity Gravity Which part of the original image to include when the resulting image is smaller than the original or the proportions do not match.

Return Value

Fill

static Fill limitFill(int|float|string|null $width = null, int|float|null $height = null, Gravity $gravity = null)

Same as the Fill::fill mode, but only if the original image is larger than the specified resolution limits, in which case the image is scaled down to fill the given width and height without distorting the image, and then the dimension that exceeds the request is cropped.

If the original dimensions are smaller than the requested size, it is not resized at all.

This prevents upscaling.

Parameters

Name Type Description
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.
$gravity Gravity Which part of the original image to include when the resulting image is smaller than the original or the proportions do not match.

Return Value

Fill

See also

Fill::fill

static FillPad fillPad(int|float|string|null $width = null, int|float|null $height = null, FocalGravity|string $gravity = null, string|ColorValue $background = null)

Tries to prevent a "bad crop" by first attempting to use the fill mode, but adding padding if it is determined that more of the original image needs to be included in the final image.

Especially useful if the aspect ratio of the delivered image is considerably different from the original's aspect ratio.

Only supported in conjunction with Automatic cropping (Gravity::auto())

Parameters

Name Type Description
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.
$gravity FocalGravity|string Specifies which part of the original image to include.
$background string|ColorValue The background color of the image.

Return Value

FillPad

See also

Gravity::auto

static Crop crop(int|float|string|null $width = null, int|float|null $height = null, Gravity $gravity = null, int|float|X $x = null, int|float|Y $y = null)

Extracts a region of the given width and height out of the original image.

Parameters

Name Type Description
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.
$gravity Gravity Which part of the original image to include.
$x int|float|X Horizontal position for custom-coordinates based cropping
$y int|float|Y Vertical position for custom-coordinates based cropping

Return Value

Crop

static Crop thumbnail(int|float|string|null $width = null, int|float|null $height = null, Gravity $gravity = null, int|float|X $x = null, int|float|Y $y = null)

The thumb cropping mode is specifically used for creating image thumbnails from either face or custom coordinates, and must always be accompanied by the gravity qualifier set to one of the face detection or custom values.

Parameters

Name Type Description
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.
$gravity Gravity Which part of the original image to include.
$x int|float|X Horizontal position for custom-coordinates based cropping
$y int|float|Y Vertical position for custom-coordinates based cropping

Return Value

Crop

static Imagga imaggaCrop(int|float|string|null $width = null, int|float|null $height = null)

Generates the best cropped version of the original image using the Imagga add-on.

If no dimensions specified, Imagga automatically defines the best crop resolution.

Parameters

Name Type Description
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.

Return Value

Imagga

See also

https://cloudinary.com/documentation/imagga_crop_and_scale_addon

static Imagga imaggaScale(int|float|string|null $width = null, int|float|null $height = null)

Generates a smartly scaled image that perfectly fits the requested dimensions.

Parameters

Name Type Description
$width int|float|string|null The required width of a transformed asset.
$height int|float|null The required height of a transformed asset.

Return Value

Imagga

See also

https://cloudinary.com/documentation/imagga_crop_and_scale_addon