FormatParser.Image (format_parser v2.14.0)

Copy Markdown

An Image struct and functions.

The Image struct contains the fields format, width_px, height_px, intrinsics and nature.

Supported Formats

FormatExtensionWidth/HeightIntrinsics
:png.pngbit_depth, color_type, compression_method, filter_method, interlace_method, crc
:jpg.jpg, .jpeg-
:gif.gif-
:bmp.bmp-
:tif.tif, .tiff-
:psd.psd-
:ico.iconum_color_palette, color_planes, bits_per_pixel
:cur.curnum_color_palette, hotspot_horizontal_coords, hotspot_vertical_coords
:cr2.cr2date_time, model, preview_byte_count, preview_offset
:nef.nefdate_time, model, preview_byte_count, preview_offset
:webp.webp--
:heic.heic--
:avif.avif--
:svg.svg--
:jb2.jb2--
:xcf.xcf--
:exr.exr--

Summary

Types

t()

A struct representing a parsed image file.

Functions

Parses an image file or result.

Types

t()

@type t() :: %FormatParser.Image{
  format: atom() | nil,
  height_px: integer() | nil,
  intrinsics: map(),
  nature: atom(),
  width_px: integer() | nil
}

A struct representing a parsed image file.

Fields

  • :format - The image format as an atom (e.g., :png, :jpg, :gif)
  • :width_px - The image width in pixels, or nil if not available
  • :height_px - The image height in pixels, or nil if not available
  • :nature - Always :image for image files
  • :intrinsics - A map containing format-specific metadata

Functions

parse(file)

@spec parse({:error, binary()} | binary() | any()) :: any()

Parses an image file or result.

  • If given a tuple {:error, file} where file is a binary, attempts to parse the image from the file.
  • If given a binary file, attempts to parse the image from the file.
  • For any other input, returns the input as-is.

Examples

iex> parse("image.png") # Parsed image result

iex> parse({:error, "image.png"}) # Parsed image result

iex> parse(:some_other_result) :some_other_result