CE.SDK for Node.js shines when you want to automate batch server-side video edits, with no manual steps. Use the CE.SDK API to resize and scale design blocks without rendering a client editor. This guide shows how to scale video elements with Node.js so you can prepare assets, generate variants, or enforce layout rules in automated jobs.
Requirements#
- A valid CE.SDL license key (get your free trial)
- Node.js 18 or newer
- CE.SDK server package:
npm install @cesdk/node
What You’ll Learn#
- Scale a video block uniformly or along a single axis.
- Scale blocks together while keeping their relative layout.
- Lock scaling and transformations in templates.
When to Use#
Server-side scaling helps when you need to:
- Emphasise or de-emphasise a clip in a composition.
- Fit footage to a free-form layout without cropping.
- Drive pinch-to-zoom gestures or responsive designs.
How Scaling Works#
Scaling uses the scale(block, scale:number, anchorX, anchorY) function, with the following parameters:
| Parameter | Description | Values |
|---|---|---|
block | Handle (ID) of the block to scale. | string |
scale | Scale factor to apply. | 1.0 keeps the original size. >1.0 enlarges the block.< 1.0 shrinks it. |
anchorX anchorY | Relative width position Relative height position | Top = 0 Center = 0.5 Bottom = 1 Defaults = 0 |
For example:
- A value of
1.0sets the original block’s size. - A value of
2.0makes the block twice as large.
Scale a Video Uniformly#
Scaling uniformly keeps the video’s aspect ratio intact while making it larger or smaller. This allows for applying zoom levels without stretching or squashing the content. For example:
engine.block.scale(blockId, 1.5);The preceding code:
- Scales the video to 150% of its original size.
- Doesn’t change the origin anchor point.
As a result, the video expands down and to the right.
Anchor Point#
By default, the anchor point for the block when scaling is the top left. The scale function has two optional parameters:
xto move the anchor point along the width.yto move the anchor point along the height.
They can have values between 0.0 and 1.0. For example:
engine.block.scale(blockId, 1.5, 0.5, 0.5)This function:
- Scales the video to 150% of its original size.
- The origin anchor point is 0.5, 0.5, so the video expands from the center.
Scale a Video Non-Uniformly#
Let the Engine Handle Scaling#
To stretch or compress only one axis, thus distorting a video, use width or height function. For example, to scale a video horizontally, you can use:
engine.block.setWidthMode(blockId, 'Absolute');const width = engine.block.getWidth(blockId) * 1.5;engine.block.setWidth(blockId, width, true );The preceding code:
- Sets the width position as
'Absolute'so width changes use a fixed pixel value instead of a relative layout mode. - Reads the current width and multiplies it by 1.5 to compute a new width that’s 150% of the original.
- Writes the new width back to the block while keeping height in proportion when available.
As a result, it stretches the element horizontally by the calculated factor:
Use this to:
- Create panoramic crops.
- Compensate for aspect ratios during automation.
2. Combine Crop-Scale with a Size Change#
Use setCropScale to explicitly crop the video vertically or horizontally. For example, to create a panoramic video:
await engine.block.setCropScaleX(blockId, 1.5);await engine.block.setWidthMode(blockId, 'Absolute');const newWidth = (await engine.block.getWidth(blockId)) * 1.5;await engine.block.setWidth(blockId, newWidth);The preceding code:
- Expands the crop horizontally, so the video content is effectively stretched 150% along the X axis.
- Switches the block to absolute sizing so width updates use a concrete pixel value instead of a responsive mode.
- Reads the block’s current width, and multiplies it by 1.5 to compute the target width after the stretch.
- Writes that new width back to the block so its frame matches the stretched content.
Respect the Existing Crop#
Since the crop defines what portion of the clip stays visible, stretching the block without preserving that crop will reveal unwanted areas or cut off the focal point. Respecting the existing crop keeps the creative intent intact while you change the scale.
await engine.block.setCropScaleX(blockId, 1.5);await engine.block.setWidthMode(blockId, 'Absolute');const newWidth = (await engine.block.getWidth(blockId)) * 1.5;await engine.block.setWidth(blockId, newWidth, true);In the preceding code, setting maintainCrop: true:
- Keeps the visible region intact.
- Avoids additional distortion.
Consider using setCropScaleX if a template already uses cropping to frame a subject or hide a watermark.
Scale Clips Together#
Group blocks to scale them proportionally:
const groupId = engine.block.group([blockId, textId]);engine.block.scale(groupId, 1.75, 0.75, 0.5)The preceding code scales the entire group to 75%. Call engine.block.findAllProperties(groupId) if you are unsure whether a block exposes width/height.
Lock Scaling in Templates#
Lock scaling when you must preserve a template’s layout. This is useful for:
- Brand assets
- Campaign creatives
- Collaboration workflows
- Fixed dimensions swapping editors
When working with templates, prevent users from scaling blocks by turning off the layer/resize scope:
// Prevent scaling/resizing of a blockengine.block.setScopeEnabled(blockId, 'layer/resize', false);Lock All Transformations#
Available block transformations are the following:
- Move
- Resize
- Rotate
To lock all transformations, use the following function:
// Lock all transformsengine.block.setTransformLocked(blockId, true);To check if scaling is currently allowed, log the output if isScopeEnabled:
// Check if resize is enabledconst canResize = engine.block.isScopeEnabled(blockId, 'layer/resize');console.log('layer/resize scope enabled?', canResize);Troubleshooting#
| Issue | Resolution |
|---|---|
Property not found when scaling | Read width/height first (findAllProperties) and update those values instead of transform keys. |
| Elements distort unexpectedly | Keep the height in sync with the width unless you intentionally stretch. |
| Export shows the original size | Confirm that the code appends the block to a page before scaling, and reuse the updated page when exporting. |
API References in this Guide#
| API | Usage |
|---|---|
block.scale | Performs uniform or anchored scaling on blocks and groups. |
block.setWidthMode | Enables absolute sizing before changing a single axis. |
block.getWidth | Reads the current width before non-uniform scaling. |
block.setWidth | Writes the adjusted width after single-axis scaling. |
block.setCropScaleX | Pairs directional scaling with crop adjustments. |
block.group | Groups blocks so they scale together. |
block.findAllProperties | Discovers available properties before scaling unfamiliar blocks. |
block.setScopeEnabled | Toggles the layer/resize scope to lock scaling in templates. |
block.setTransformLocked | Locks all transform scopes when templates must stay fixed. |
block.isScopeEnabled | Checks whether a block allows scaling. |