Resize
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
BaseResize constructor.
Adds the qualifier to the action.
Adds qualifiers to the action.
Adds (sets) generic (raw) action.
Sets the flag.
Removes the flag.
Serializes to json.
Serializes to Cloudinary URL format
Sets the width and height of the asset.
Sets the aspect ratio of the asset.
Creates a new instance using provided array of qualifiers
Sets the resize mode.
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'.
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 resize builder.
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.
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.
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.
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.
Sets the compass direction.
Sets the x offset.
Sets the y offset.
Sets the x and y offset.
Resizes the image to fill the given width and height while retaining the original aspect ratio and with all of the original image visible.
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.
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.
Sets pad position.
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.
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.
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.
Generates the best cropped version of the original image using the Imagga add-on.
Generates a smartly scaled image that perfectly fits the requested dimensions.
Details
__construct(string|CropMode $cropMode, int|string|Expression $width = null, int|string|Expression $height = null)
BaseResize constructor.
$this
addQualifier(BaseComponent $qualifier = null)
Adds the qualifier to the action.
$this
addQualifiers(array ...$qualifiers)
Adds qualifiers to the action.
BaseAction
setGenericAction(string $action)
Adds (sets) generic (raw) action.
$this
setFlag(FlagQualifier $flag, bool $set = true)
Sets the flag.
$this
unsetFlag(FlagQualifier $flag)
Removes the flag.
$this
importAction(BaseAction|null $action)
Imports (merges) qualifiers and flags from another action.
mixed
jsonSerialize()
Serializes to json.
string
__toString()
Serializes to Cloudinary URL format
DimensionsTrait
width(int|string|Expression $width)
Sets the width of the asset.
DimensionsTrait
height(int|string|Expression $height)
Sets the height of the asset.
$this
size(string $size)
Sets the width and height of the asset.
DimensionsTrait
aspectRatio(float|array|AspectRatio ...$aspectRatio)
Sets the aspect ratio of the asset.
static BaseResizeAction
fromParams(array $qualifiers)
Creates a new instance using provided array of qualifiers
BaseResizeAction
resizeMode(string|FlagQualifier $resizeMode)
Sets the resize mode.
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'.
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.
static GenericResizeTrait
generic(string $resizeName, int|float|string|null $width = null, int|float|null $height = null)
Generic resize builder.
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.
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.
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.
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.
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.
$this
offsetX(int|float|string $x)
Sets the x offset.
$this
offsetY(int|float|string $y)
Sets the y offset.
OffsetTrait
offset(int|float|string $x = null, int|float|string $y = null)
Sets the x and y offset.
$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.
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
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.
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.
$this
position(BasePosition $position)
Sets pad position.
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.
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.
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())
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.
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.
static Crop
auto(int|float|string|null $width = null, int|float|null $height = null, Gravity $gravity = null)
Automatically determines the best crop based on the gravity and specified dimensions.
If the requested dimensions are smaller than the best crop, the result is downscaled. If the requested dimensions are larger than the original image, the result is upscaled. Use this mode in conjunction with the g (gravity) parameter.
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.
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.
Constants
MAIN_QUALIFIER |
|