Variant generation system for images and videos.
This module handles the creation of different variants (thumbnails, resizes, quality adjustments) for uploaded files based on dimension configurations.
Supported Operations
Images
- Resize to specific dimensions
- Generate thumbnails (square crops)
- Quality adjustments
- Format conversion (JPEG, PNG, WebP)
Videos
- Quality variants (360p, 720p, 1080p)
- Thumbnail extraction
- Format conversion (MP4)
Dependencies
Requires external tools to be installed:
- Images: ImageMagick (
convertandidentifycommands) - Videos: FFmpeg
Summary
Functions
Generates a specific variant for a file.
Generates variants for a file based on enabled dimensions.
Functions
Generates a specific variant for a file.
Parameters
file- The file structdimension- The dimension configuration
Returns
{:ok, file_instance}- Generated variant{:error, reason}- Error if generation fails
Generates variants for a file based on enabled dimensions.
Parameters
file- The file struct to generate variants foropts- Options for variant generation
Options
:dimensions- List of specific dimensions to generate (default: all enabled)
Variant generation is always synchronous from the caller's perspective.
Internally process_variants/2 parallelizes the per-dimension work via
Task.await_many/2 with a 10-minute cap. Callers that need fire-and-forget
semantics should enqueue the work via Oban (see process_file_job.ex).
Returns
{:ok, variants}- List of generated file instances{:error, reason}- Error if generation fails