Expresso.Image (expresso v0.1.0)

Copy Markdown View Source

The data URI of an image file

The document of a deck is one file, so an image cannot be a second file. This module reads an image at render time and makes a data URI from the bytes. The img element of Expresso.Element.Image then holds the image.

media_type/1 gives the media type of a path, and data_uri/1 gives the full URI. The extension of the path gives the media type.

Summary

Functions

Make the data URI of an image path

Make the data URI of an image path, or raise

Return the extensions of the image types that Expresso knows

Give the media type of an image path

Functions

data_uri(path)

@spec data_uri(Path.t()) :: {:ok, String.t()} | {:error, String.t()}

Make the data URI of an image path

A relative path starts from the working directory of the command. Expresso.PathTransformer already joined the path of an image to the root option of the deck. The function reads the file, and it gives an error tuple for a file that it cannot read.

data_uri!(path)

@spec data_uri!(Path.t()) :: String.t()

Make the data URI of an image path, or raise

Expresso.Element.Image calls this function, because a render function has no way to report an error tuple.

extensions()

@spec extensions() :: [String.t()]

Return the extensions of the image types that Expresso knows

media_type(path)

@spec media_type(Path.t()) :: {:ok, String.t()} | {:error, String.t()}

Give the media type of an image path

The function reads the extension of the path, and it does not read the file. An extension that this module does not know gives an error tuple with the list of the extensions.