# `PhoenixKit.Modules.Storage.Dimension`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.165/lib/modules/storage/schemas/dimension.ex#L1)

Schema for dimension presets for automatic file variant generation.

Dimensions define target sizes and quality settings for automatically
generating different versions of uploaded images and videos.

## Fields

- `name` - Unique name for this dimension (e.g., "thumbnail", "medium")
- `width` - Target width in pixels (nullable = maintain aspect ratio)
- `height` - Target height in pixels (nullable = maintain aspect ratio)
- `quality` - Quality setting (1-100 for images, CRF 0-51 for videos)
- `format` - Output format override (nullable = preserve original)
- `applies_to` - What this dimension applies to: "image", "video", or "both"
- `enabled` - Whether this dimension is active
- `order` - Display order in admin interface

## Quality Settings

### Images (JPEG, WebP, PNG)
- Range: 1-100
- 85 = Good quality (default)
- 95 = High quality
- 70 = Medium quality

### Videos (MP4, WebM)
- Range: 0-51 (CRF - Constant Rate Factor)
- Lower = Higher quality
- 23 = Good quality (default)
- 18 = High quality
- 28 = Medium quality

## Examples

    # Image thumbnail
    %Dimension{
      name: "thumbnail",
      width: 150,
      height: 150,
      quality: 85,
      format: "jpg",
      applies_to: "image",
      enabled: true,
      order: 1
    }

    # Video 720p variant
    %Dimension{
      name: "720p",
      width: 1280,
      height: 720,
      quality: 23,
      format: "mp4",
      applies_to: "video",
      enabled: true,
      order: 2
    }

    # Responsive image (maintain aspect ratio)
    %Dimension{
      name: "large",
      width: 1920,
      height: nil,  # Maintain aspect ratio
      quality: 85,
      format: nil,  # Preserve original
      applies_to: "image",
      enabled: true,
      order: 3
    }

# `applies_to_images?`

Returns whether this dimension applies to images.

# `applies_to_videos?`

Returns whether this dimension applies to videos.

# `changeset`

Changeset for creating or updating a dimension.

## Required Fields

- `name`
- `applies_to`
- `width` - Required when `maintain_aspect_ratio` is true or false

## Optional Fields

- `height` - Required when `maintain_aspect_ratio` is false (fixed dimensions)
- `maintain_aspect_ratio` - Whether to preserve aspect ratio (default: true)

## Validation Rules

- Name must be unique
- Width must be specified (always required)
- Height must be specified when `maintain_aspect_ratio` is false
- Width and height must be positive integers
- Quality must be between 1-100 for images or 0-51 for videos
- Applies to must be one of: "image", "video", "both"
- Format must be valid if specified
- Order must be >= 0

# `description`

Returns a human-readable description of this dimension.

# `preserve_aspect_ratio?`

Returns whether this dimension preserves aspect ratio.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
