Skip to main content
Runtime modules are the built-in capabilities you call from automations on the foundation, and the image module is one of them. It reads the dimensions of a base64 image and downscales it under a size limit, inside the runtime: the image never leaves it, and no Custom Code function is needed. Typical use: bringing an image under a model provider’s pixel limit before sending it to the model. It reads png, jpeg, gif and webp images. Any other format (svg, tiff, heif, pdf…) is refused before being decoded.

dimensions

Read the format and dimensions of an image from its header only, without decoding the image.
Returns { format, width, height }, or null when the data is empty, not one of the four formats, or its header is unreadable. width and height are the stored dimensions: a phone photo shot in portrait can be stored in landscape with an EXIF orientation, and reports its stored sides here. The longest side is the same either way.

fit

Downscale an image so that neither side exceeds maxSide pixels, and optionally its encoded size maxBytes. The aspect ratio is kept, and the image is never enlarged.
The EXIF orientation is applied, so a phone photo comes out the right way up, without an orientation tag. When the image already fits, keeps its format, has no orientation to apply and is within maxBytes, it is returned unchanged with resized: false. Only its header is read then: a corrupt image can come back unchanged. Otherwise it is returned rewritten: An image that cannot be fitted does not stop the automation. fit returns { error } instead, with a message for some of them (unreadable, timeout, too_costly, busy, output_too_heavy): The memory and time a fit takes grow with the output size: a maxSide close to what the consumer of the image actually uses keeps them low. Model providers keep no more than 1568 to 3072 px per side, so a larger maxSide only makes the image heavier. A runtime instance shares a memory budget between the images it fits. Before decoding, each image reserves what it takes, from its header: about 100 MB for a baseline JPEG or a plain PNG (phone photos, screenshots) and 300 MB for a progressive JPEG, an interlaced PNG, a webp or a gif, which are decoded whole, both up to 2048 px in the image’s own format; more for a larger maxSide or a webp output. An image already within maxSide only reserves the reading of its header, and is decoded only if its orientation must be applied. An image waits while the budget is full, at most three are fitted at once, and the reservations never exceed the memory the runtime container has left. The first image kept waiting for lack of memory goes before the ones that arrive after it.
On a self-hosted platform, the limits of fit are set on the runtime: IMAGE_MAX_INPUT_BYTES, IMAGE_MAX_INPUT_PIXELS, IMAGE_FIT_MEMORY_BUDGET, IMAGE_MEMORY_PRESSURE_PERCENT, IMAGE_MAX_CONCURRENT_FITS, IMAGE_FIT_QUEUE_TIMEOUT_SECONDS, IMAGE_FIT_TIMEOUT_SECONDS and IMAGE_LIBVIPS_THREADS. See Environment variables.