PhoenixKit.Modules.Storage.Dimension (phoenix_kit v2.60.2)

Copy Markdown View Source

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
}

Summary

Functions

Returns whether this dimension applies to images.

Returns whether this dimension applies to videos.

The standard sizes that always keep the aspect ratio.

Changeset for creating or updating a dimension.

How a fixed rendition can be cropped: around the middle, or around the subject.

Returns a human-readable description of this dimension.

The side a rendition that keeps proportions can fix: its width, or its height.

Whether dimension keeps proportions and fixes its height (the width follows each photo: a horizontal panorama's thumbnail).

Whether dimension is cropped around the photo's focal point: a fixed box (not one that keeps proportions) whose crop mode is focus.

Returns whether this dimension preserves aspect ratio.

Which pictures a rendition can be made for: every one, the wide ones, the tall ones.

Whether dimension is one of the standard sizes.

The sizes every variant set has; they cannot be renamed or deleted.

Types

t()

@type t() :: %PhoenixKit.Modules.Storage.Dimension{
  __meta__: term(),
  alternative_formats: [String.t()],
  applies_to: String.t() | nil,
  crop_mode: String.t(),
  enabled: boolean(),
  fit_by: String.t(),
  format: String.t() | nil,
  height: integer() | nil,
  inserted_at: DateTime.t() | nil,
  maintain_aspect_ratio: boolean(),
  name: String.t() | nil,
  order: integer(),
  quality: integer() | nil,
  shape: String.t(),
  updated_at: DateTime.t() | nil,
  uuid: UUIDv7.t() | nil,
  variant_set_uuid: UUIDv7.t() | nil,
  width: integer() | nil
}

Functions

applies_to_images?(arg1)

Returns whether this dimension applies to images.

applies_to_videos?(arg1)

Returns whether this dimension applies to videos.

aspect_slots()

The standard sizes that always keep the aspect ratio.

changeset(dimension, attrs)

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

crop_modes()

How a fixed rendition can be cropped: around the middle, or around the subject.

description(dimension)

Returns a human-readable description of this dimension.

fit_sides()

The side a rendition that keeps proportions can fix: its width, or its height.

fixed_height?(dimension)

Whether dimension keeps proportions and fixes its height (the width follows each photo: a horizontal panorama's thumbnail).

focus_crop?(dimension)

Whether dimension is cropped around the photo's focal point: a fixed box (not one that keeps proportions) whose crop mode is focus.

preserve_aspect_ratio?(dimension)

Returns whether this dimension preserves aspect ratio.

shapes()

Which pictures a rendition can be made for: every one, the wide ones, the tall ones.

standard_slot?(dimension)

Whether dimension is one of the standard sizes.

standard_slots()

The sizes every variant set has; they cannot be renamed or deleted.