PhoenixKit.Modules.Storage.VariantNaming (phoenix_kit v1.7.102)

Copy Markdown View Source

Utilities for naming and parsing storage variant names.

Variant names follow the convention:

  • Primary: "medium" (dimension name only)
  • Alternative format: "medium_webp" (dimension name + format suffix)

The parser splits on the last underscore and checks whether the suffix is a known image format. If it is, the variant is an alternative format.

Summary

Functions

Returns the list of known image format suffixes.

Returns the MIME type for a format string.

Parses a variant name into {base_dimension, format}.

Builds a variant name from a base dimension name and format.

Functions

known_formats()

Returns the list of known image format suffixes.

mime_type_for_format(arg1)

Returns the MIME type for a format string.

Examples

iex> mime_type_for_format("webp")
"image/webp"

iex> mime_type_for_format("avif")
"image/avif"

parse_variant_name(variant_name)

Parses a variant name into {base_dimension, format}.

Examples

iex> parse_variant_name("medium")
{"medium", nil}

iex> parse_variant_name("medium_webp")
{"medium", "webp"}

iex> parse_variant_name("video_thumbnail")
{"video_thumbnail", nil}

iex> parse_variant_name("thumbnail_avif")
{"thumbnail", "avif"}

variant_name(base, format)

Builds a variant name from a base dimension name and format.

Examples

iex> variant_name("medium", nil)
"medium"

iex> variant_name("medium", "webp")
"medium_webp"