Class ImageCropStyle

  • ImageCropStyle allows cropping images within Google Apps Script, but not resizing them directly.

  • Two main methods, setAspectRatio and setImageCropType, provide control over the cropping process.

  • setAspectRatio is applicable only when using the RECTANGLE_CUSTOM crop type and requires a positive ratio value.

  • setImageCropType lets you choose the shape of the crop, with SQUARE being the default option.

  • Both methods return the ImageCropStyle object, enabling method chaining for streamlined code.

ImageCropStyle

A class that represents a crop style that can be applied to image components. You can't set the size of an image or resize it, but you can crop the image.

Methods

MethodReturn typeBrief description
setAspectRatio(ratio)ImageCropStyleSets the aspect ratio to use if the crop type is RECTANGLE_CUSTOM.
setImageCropType(type)ImageCropStyleSets the crop type for the image.

Detailed documentation

setAspectRatio(ratio)

Sets the aspect ratio to use if the crop type is RECTANGLE_CUSTOM. The ratio must be a positive value.

Parameters

NameTypeDescription
ratioNumberThe ratio to apply.

Return

ImageCropStyle — This object, for chaining.

Throws

Error — if the input is negative or zero.


setImageCropType(type)

Sets the crop type for the image. Default is SQUARE.

Parameters

NameTypeDescription
typeImageCropTypeThe crop type.

Return

ImageCropStyle — This object, for chaining.