Modify Crop
In this example, we will show you how to use the CreativeEditor SDK's CreativeEngine to modify a blocks crop through the block
API.
Setup#
This example uses the headless CreativeEngine. See the Setup article for a detailed guide.
To get started right away, you can also access the block
API within a running CE.SDK instance via cesdk.engine.block
.
Check out the APIs Overview to see that illustrated in more detail.
Common Properties#
Common properties are properties that occur on multiple block types. For instance, fill color properties are available for all the shape blocks and the text block. That's why we built convenient setter and getter functions for these properties. So you don't have to use the generic setters and getters and don't have to provide a specific property path. There are also has*
functions to query if a block supports a set of common properties.
Crop#
Manipulate the cropping region of a block by setting its scale, rotation, and translation.
supportsCrop(id: DesignBlockId): boolean
Query if the given block has crop properties.
id
: The block to query.- Returns true, if the block has crop properties.
setCropScaleX(id: DesignBlockId, scaleX: number): void
Set the crop scale in x direction of the given design block. Required scope: 'layer/crop'
id
: The block whose crop should be set.scaleX
: The scale in x direction.
setCropScaleY(id: DesignBlockId, scaleY: number): void
Set the crop scale in y direction of the given design block. Required scope: 'layer/crop'
id
: The block whose crop should be set.scaleY
: The scale in y direction.
setCropScaleRatio(id: DesignBlockId, scaleRatio: number): void
Set the crop scale ratio of the given design block. This will uniformly scale the content up or down. The center of the scale operation is the center of the crop frame. Required scope: 'layer/crop'
id
: The block whose crop should be set.scaleRatio
: The crop scale ratio.
setCropRotation(id: DesignBlockId, rotation: number): void
Set the crop rotation of the given design block. Required scope: 'layer/crop'
id
: The block whose crop should be set.rotation
: The rotation in radians.
setCropTranslationX(id: DesignBlockId, translationX: number): void
Set the crop translation in x direction of the given design block. Required scope: 'layer/crop'
id
: The block whose crop should be set.translationY
: The translation in y direction.
setCropTranslationY(id: DesignBlockId, translationY: number): void
Set the crop translation in y direction of the given design block. Required scope: 'layer/crop'
id
: The block whose crop should be set.translationY
: The translation in y direction.
adjustCropToFillFrame(id: DesignBlockId, minScaleRatio: number): number
Adjust the crop position/scale to at least fill the crop frame.
id
: The block whose crop scale ratio should be queried.minScaleRatio
: The minimal crop scale ratio to go down to.
setContentFillMode(id: DesignBlockId, mode: ContentFillMode): void
Set a block's content fill mode. Required scope: 'layer/crop'
id
: The block to update.mode
: The content fill mode mode: crop, cover or contain.
resetCrop(id: DesignBlockId): void
Resets the manually set crop of the given design block. The block's content fill mode is set to 'Cover'. If the block has a fill, the crop values are updated so that it covers the block. Required scope: 'layer/crop'
id
: The block whose crop should be reset.
getCropScaleX(id: DesignBlockId): number
Get the crop scale on the x axis of the given design block.
id
: The block whose scale should be queried.- Returns The scale on the x axis.
getCropScaleY(id: DesignBlockId): number
Get the crop scale on the y axis of the given design block.
id
: The block whose scale should be queried.- Returns The scale on the y axis.
flipCropHorizontal(id: DesignBlockId): void
Adjusts the crop in order to flip the content along its own horizontal axis.
block
: The block whose crop should be updated.
flipCropVertical(id: DesignBlockId): void
Adjusts the crop in order to flip the content along its own vertical axis.
block
: The block whose crop should be updated.
getCropScaleRatio(id: DesignBlockId): number
Get the crop scale ratio of the given design block.
id
: The block whose crop scale ratio should be queried.- Returns The crop scale ratio.
getCropRotation(id: DesignBlockId): number
Get the crop rotation of the given design block.
id
: The block whose crop rotation should be queried.- Returns The crop rotation.
getCropTranslationX(id: DesignBlockId): number
Get the crop translation on the x axis of the given design block.
id
: The block whose translation should be queried.- Returns The translation on the x axis.
getCropTranslationY(id: DesignBlockId): number
Get the crop translation on the y axis of the given design block.
id
: The block whose translation should be queried.- Returns The translation on the y axis.
supportsContentFillMode(id: DesignBlockId): boolean
Query if the given block has a content fill mode.
id
: The block to query.- Returns true, if the block has a content fill mode.
getContentFillMode(id: DesignBlockId): ContentFillMode
Query a block's content fill mode.
id
: The block to query.- Returns The current mode: crop, cover or contain.