Output functions
Basic functions for output and formatting.
scaleImage(bytes, width, height, options)
Scales an image byte array to a target size and returns the scaled image as bytes. Supports several scaling modes and lets you preserve or convert between JPEG, PNG, WebP and AVIF output formats. The optional parameters (mode, quality, format) can be supplied positionally or as a single options object — see the examples below.
Note: scaleImage runs server-side and is controlled entirely by your own code. It is NOT subject to Images.SizePolicy in site.json — only URL-based scaling (/photo.jpg/WxHxM/...) is enforced against the allowed-sizes policy. See the 'Image output formats (WebP / AVIF)' section on the Image scaling page. scaleImage is not subject to the image size policy; to enable and register the sizes that ARE enforced (URL-based scaling), see the KB article Restrict and register image sizes.