rw.resizeResource
The rw.resizeResource() function resizes an image resource to a specified width, returning the path to the resized image. This is essential for creating responsive images and thumbnails.
Syntax
const resizedPath = rw.resizeResource(resource, width);Parameters
Parameter
Type
Description
resource
Object
An image resource object from rw.props
width
Number
Target width in pixels
Returns
A string path to the resized image.
Basic Example
const transformHook = (rw) => {
const { image } = rw.props;
// Create a thumbnail at 400px wide
const thumbnail = rw.resizeResource(image, 400);
rw.setProps({
thumbnail
});
};
exports.transformHook = transformHook;Common Patterns
Multiple Sizes
Retina/HiDPI Support
Double the width for retina displays:
Responsive Images with Breakpoints
Gallery Thumbnails
Responsive Image with Custom Sizes
Template Usage
Notes
Always multiply width by 2 for retina display support
The function returns a path string, not the full image object
Works with any image resource from properties or collections
Efficiently caches resized images
Last updated
Was this helpful?

