Search documentation of phoenix_kit

# PhoenixKit.Storage.VariantGenerator (phoenix_kit v1.6.19)

View Source

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 (`convert` and `identify` commands)
- Videos: FFmpeg

# Summary

## Functions

generate_variant(file, dimension)

Generates a specific variant for a file.

generate_variants(file, opts \\ [])

Generates variants for a file based on enabled dimensions.

# Functions

# generate_variant(file, dimension)

Generates a specific variant for a file.

## Parameters

- `file` - The file struct
- `dimension` - The dimension configuration

## Returns

- `{:ok, file_instance}` - Generated variant
- `{:error, reason}` - Error if generation fails

# generate_variants(file, opts \\ [])

Generates variants for a file based on enabled dimensions.

## Parameters

- `file` - The file struct to generate variants for
- `opts` - Options for variant generation

## Options

- `:async` - Whether to generate variants asynchronously (default: true)
- `:dimensions` - List of specific dimensions to generate (default: all enabled)

## Returns

- `{:ok, variants}` - List of generated file instances
- `{:error, reason}` - Error if generation fails