Presets
Presets are named bundles of processing options that let you define reusable transformation recipes. Instead of repeating complex option chains in every URL, reference a preset by name. This document explains how to configure, use, and manage presets effectively.
Overview
Presets address common challenges in image transformation workflows:
- Consistency – Apply identical transformations across your application
- Maintainability – Update transformations globally by changing one definition
- Simplicity – Shorter URLs that are easier to read and debug
- Governance – Control which transformations are permitted
- Security – Prevent arbitrary transformation requests in presets-only mode
Syntax:
Configuration
Define presets via the IMGFLUX_PRESETS environment variable. Each preset maps a name to a slash-separated list of processing options.
Basic Format
Single Preset
This creates a preset called thumbnail that resizes images to 150×150 using the fit mode and outputs at 80% quality.
Multiple Presets
Separate multiple presets with commas. Each preset name must be unique.
Complex Presets
Presets can include any valid processing option:
The Default Preset
A preset named default receives special treatment—it applies automatically to every request before URL-specific options or named presets.
Example
With this configuration, all images will:
- Use 90% quality (unless overridden)
- Apply 1.0 DPR scaling (unless overridden)
- Honor EXIF orientation by default
URL options and named presets can still override these defaults.
Use Cases for Default Presets
- Organization-wide quality standards – Enforce minimum quality across all images
- Default DPR handling – Apply consistent device pixel ratio scaling
- Format preferences – Set a default output format
- Performance baselines – Apply sensible compression defaults
- Security policies – Always apply certain safeguards
URL Usage
Basic Preset Reference
The pr: shorthand is equivalent to preset: and saves bytes in URLs.
The source URL segment that follows the preset can use either encoding style supported by imgFlux:
- Base64 URL-safe – append an optional
.<ext>suffix to force an output format - Plain URL – start the segment with
plain/and percent-encode the URL, optionally adding@<ext>
Choose whichever form matches your signing tooling; presets work the same either way.
Chaining Presets
Multiple presets can be combined:
Later presets override earlier ones if they set the same parameter.
Mixing Presets and Options
Presets expand into options, so you can mix them freely:
The explicit quality:95 overrides the quality setting from the thumbnail preset.
Signed URLs with Presets
Presets are part of the URL path and must be included in the signature:
Presets-Only Mode
Enable strict governance by setting IMGFLUX_ONLY_PRESETS=true. In this mode, imgFlux rejects URLs that contain non-preset processing options.
Configuration
Allowed Requests
Rejected Requests
All rejected requests return 400 Bad Request with an error message.
Use Cases for Presets-Only Mode
- Multi-tenant platforms – Prevent users from creating arbitrary transformations
- Cost control – Limit processing to pre-approved operations
- Security hardening – Reduce attack surface by disallowing custom options
- Compliance – Enforce transformation policies for regulated content
- Client SDKs – Simplify integration by providing fixed preset names
Exception: Default Preset
If a default preset exists, requests with no processing options at all will still succeed in presets-only mode, because the default preset is implicitly applied:
Preset Definition Best Practices
1. Use Descriptive Names
Descriptive names make URL generation code self-documenting.
2. Include Common Options
Including quality, format, and sharpening in presets reduces surprises.
3. Organize by Use Case
Group presets by domain or feature area.
4. Version Your Presets
This allows gradual migration when changing transformation logic.
Common Preset Patterns
Responsive Image Sets
Define presets for each breakpoint:
Usage in HTML:
Avatar Sizes
Format Variants
Combine with other presets:
Performance Tiers
Watermarking
Preset Expansion Order
Understanding expansion order helps predict the final result when combining multiple presets and options.
Expansion sequence:
- Default preset (if defined) expands first
- URL options/presets expand left-to-right
- Later values override earlier ones for the same parameter
Example
Configuration:
URL:
Expansion steps:
default=quality:80→quality:80preset:thumbnail→trim:150:150q90(quality now 90)quality:95→ (quality now 95, overrides preset)preset:sharp→sharpen:1.5
Final options: trim:150:150q95/sharpen:1.5
Override Strategy
Later options always win:
This makes it safe to set defaults and override selectively.
Troubleshooting
Preset Not Found Error
Symptom: 400 Bad Request with message "unknown preset: xyz"
Causes:
- Preset name misspelled in URL
- Preset not defined in
IMGFLUX_PRESETS - Environment variable not loaded (server restart needed)
Fix:
Unexpected Transformation Results
Symptom: Image doesn't match expected dimensions/quality
Causes:
- Option override you didn't expect
- Default preset applying unintended options
- Multiple presets with conflicting settings
Debug:
Presets-Only Mode Rejecting Valid Presets
Symptom: 400 Bad Request even with preset:name in URL
Causes:
- Extra processing options mixed with preset
- Typo:
preset_nameinstead ofpreset:name - Space or special character in preset name
Fix:
Preset Changes Not Applied
Symptom: Old preset definition still being used
Cause: Environment variable not reloaded
Fix:
Caching with Presets
Cached images are stored by full URL path (including expanded preset). Changing a preset definition invalidates the cache for all URLs using that preset:
Cache invalidation strategy:
-
Version preset names when changing definitions:
-
Drain cache gradually by updating application code to use new preset name
-
Purge cache explicitly if immediate update is required
Security Considerations
Preset Definition Protection
Presets are defined server-side and cannot be modified by clients. This makes them safer than allowing arbitrary options:
Signature Coverage
Preset names are part of the URL path and must be included in the HMAC signature. This prevents:
- Preset name tampering
- Substituting one preset for another
- Adding presets to unsigned URLs
See Also
- Processing Options – Complete options reference
- Configuration – Environment variable details
- URL Structure – URL signing and encoding
- Caching – Cache behavior with presets
- Performance – Optimization strategies