Optimize images
optimize_imagesOptimize images for the web by downscaling to a max width, converting to WebP/JPEG/AVIF, and generating responsive srcset variants, replacing heavy originals to keep production lean.
Instructions
Resize and re-encode images for production web use via sharp: downscale to max_width (default 1920, never upscales), convert to webp (default; jpeg/avif available), auto-apply EXIF rotation, optionally emit extra srcset variants (widths → name-.webp). By default the source file is replaced by the optimized output so heavy originals don't leak into production; keep_originals: true preserves them. Accepts files or directories. Returns final dimensions (use them for width/height) and sizes before/after. Typical landing use: generate images into assets/img, then optimize the whole directory in one call.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| paths | Yes | Image files and/or directories (absolute, or relative to the project cwd). A directory takes every supported image at its top level (png/jpg/webp/avif/tiff). | |
| format | No | Output format. Default: webp (best size/support balance for the web). | |
| widths | No | Extra downsized variants for srcset, e.g. [800] → name-800.webp next to the main file. Variants wider than the source are skipped. | |
| quality | No | Encode quality. Defaults: webp/jpeg 80, avif 60. | |
| max_width | No | Resize down to this width, keeping aspect ratio; never upscales. Default: 1920. | |
| keep_originals | No | Keep source files after conversion. Default false: the source is replaced by the optimized output (prevents heavy originals leaking into production). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| files | Yes | Optimized files with their output variants (sizes for <img> width/height). | |
| skipped | Yes | Inputs that could not be processed. | |
| total_kb_after | Yes | Total size of main outputs (srcset variants excluded). | |
| total_kb_before | Yes |