View Source Appwrite.Consts.ImageFormat (appwrite v0.1.3)

Provides constants and validation functions for image formats.

This module defines the image formats supported by the system, such as JPG, JPEG, GIF, PNG, and WebP. Helper functions are included to validate these formats, ensuring only recognized image formats are used.

Summary

Functions

Returns true if the given format is a valid image format.

Guard clause to check if a given image format is a valid image format code.

Validates the given format and returns {:ok, format} if it is valid, or {:error, "Invalid image format"} otherwise.

Returns the given format if it is valid. Raises an ArgumentError if the format is invalid.

Functions

Link to this function

is_valid_format?(format)

View Source
@spec is_valid_format?(String.t()) :: boolean()

Returns true if the given format is a valid image format.

Examples

iex> ImageFormat.is_valid_format?("jpg")
true

iex> ImageFormat.is_valid_format?("bmp")
false
Link to this macro

valid_format(image_format)

View Source (macro)
@spec valid_format(String.t()) :: boolean()

Guard clause to check if a given image format is a valid image format code.

Examples

iex> ImageFormat.valid_format("jpg")
true

iex> ImageFormat.valid_format("bmp")
false
@spec validate_format(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Validates the given format and returns {:ok, format} if it is valid, or {:error, "Invalid image format"} otherwise.

Examples

iex> ImageFormat.validate_format("png")
{:ok, "png"}

iex> ImageFormat.validate_format("bmp")
{:error, "Invalid image format"}
Link to this function

validate_format!(format)

View Source
@spec validate_format!(String.t()) :: String.t()

Returns the given format if it is valid. Raises an ArgumentError if the format is invalid.

Examples

iex> ImageFormat.validate_format!("jpg")
"jpg"

iex> ImageFormat.validate_format!("bmp")
** (ArgumentError) Invalid image format: "bmp"