class Resize extends BaseResizeAction

Determines how to crop, scale, and/or zoom the delivered asset according to the requested dimensions.

Learn more: Resizing images | Resizing videos

Methods

__construct(string|CropMode $cropMode, null $width = null, null $height = null)

BaseResize constructor.

addQualifier(BaseComponent $qualifier = null)

Adds the qualifier to the action.

addQualifiers(array ...$qualifiers)

Adds qualifiers to the action.

setGenericAction(string $action)

Adds (sets) generic (raw) action.

setFlag(FlagQualifier $flag, bool $set = true)

Sets the flag.

unsetFlag(FlagQualifier $flag)

Removes the flag.

importAction(BaseAction|null $action)

Imports (merges) qualifiers and flags from another action.

jsonSerialize()

Serializes to json.

__toString()

Serializes to Cloudinary URL format

width(int|string|Expression $width)

Sets the width of the asset.

height(int|string|Expression $height)

Sets the height of the asset.

size(string $size)

Sets the width and height of the asset.

aspectRatio(float|array|AspectRatio ...$aspectRatio)

Sets the aspect ratio of the asset.

fromParams(array $qualifiers)

Creates a new instance using provided array of qualifiers

resizeMode(string|FlagQualifier $resizeMode)

Sets the resize mode.

regionRelative()

Modifies percentage-based width & height qualifiers of overlays and underlays (e.g., 1.0) to be relative to the overlaid region. Currently regions are only defined when using gravity 'face', 'faces' or 'custom'.

relative()

Modifies percentage-based width & height qualifiers of overlays and underlays (e.g., 1.0) to be relative to the containing image instead of the added layer.

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($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

__construct(string|CropMode $cropMode, null $width = null, null $height = null)

BaseResize constructor.

Parameters

Name Type Description
$cropMode string|CropMode The crop mode.
$width null Optional. Width.
$height null Optional. Height.

$this addQualifier(BaseComponent $qualifier = null)

Adds the qualifier to the action.

Parameters

Name Type Description
$qualifier BaseComponent The qualifier to add.

Return Value

$this

$this addQualifiers(array ...$qualifiers)

Adds qualifiers to the action.

Parameters

Name Type Description
...$qualifiers array The qualifiers to add.

Return Value

$this

BaseAction setGenericAction(string $action)

Adds (sets) generic (raw) action.

Parameters

Name Type Description
$action string The generic action string.

Return Value

BaseAction

$this setFlag(FlagQualifier $flag, bool $set = true)

Sets the flag.

Parameters

Name Type Description
$flag FlagQualifier The flag to set.
$set bool Indicates whether to set(true) or unset(false) the flag instead. (Used for avoiding if conditions all over the code)

Return Value

$this

$this unsetFlag(FlagQualifier $flag)

Removes the flag.

Parameters

Name Type Description
$flag FlagQualifier The flag to unset.

Return Value

$this

$this importAction(BaseAction|null $action)

Imports (merges) qualifiers and flags from another action.

Parameters

Name Type Description
$action BaseAction|null The action to import.

Return Value

$this

mixed jsonSerialize()

Serializes to json.

Return Value

mixed

string __toString()

Serializes to Cloudinary URL format

Return Value

string

DimensionsTrait width(int|string|Expression $width)

Sets the width of the asset.

Parameters

Name Type Description
$width int|string|Expression The width in pixels.

Return Value

DimensionsTrait

DimensionsTrait height(int|string|Expression $height)

Sets the height of the asset.

Parameters

Name Type Description
$height int|string|Expression The height in pixels.

Return Value

DimensionsTrait

$this size(string $size)

Sets the width and height of the asset.

Parameters

Name Type Description
$size string The size of asset expressed as "width x height".

Return Value

$this

DimensionsTrait aspectRatio(float|array|AspectRatio ...$aspectRatio)

Sets the aspect ratio of the asset.

Parameters

Name Type Description
...$aspectRatio float|array|AspectRatio The new aspect ratio, specified as a percentage or ratio.

Return Value

DimensionsTrait

static BaseResizeAction fromParams(array $qualifiers)

Creates a new instance using provided array of qualifiers

Parameters

Name Type Description
$qualifiers array The qualifiers.

Return Value

BaseResizeAction

BaseResizeAction resizeMode(string|FlagQualifier $resizeMode)

Sets the resize mode.

Parameters

Name Type Description
$resizeMode string|FlagQualifier The resize mode. Can be set to: relative or regionRelative.

Return Value

BaseResizeAction

See also

ResizeMode::relative
ResizeMode::regionRelative

BaseResizeAction regionRelative()

Modifies percentage-based width & height qualifiers of overlays and underlays (e.g., 1.0) to be relative to the overlaid region. Currently regions are only defined when using gravity 'face', 'faces' or 'custom'.

Return Value

BaseResizeAction

BaseResizeAction relative()

Modifies percentage-based width & height qualifiers of overlays and underlays (e.g., 1.0) to be relative to the containing image instead of the added layer.

Return Value

BaseResizeAction

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($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

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

Constants

MAIN_QUALIFIER