ExPng.Image (ExPng v1.0.0)

The primary API module for ExPng, ExPng.Image provides functions for reading, editing, and saving images.

Link to this section Summary

Functions

Attempts to decode a PNG file into an ExPng.Image and returns a success tuple {:ok, image} or an error tuple explaining the encountered error.

Constructs a new image from the provided 2-dimensional list of pixels

Returns a blank (opaque white) image with the provided width and height

Writes the image to disk at filename using the provided encoding_options.

Returns a list of unique pixels values used in image.

Link to this section Types

Specs

canvas() :: [row(), ...]

Specs

error() :: {:error, String.t(), filename()}

Specs

filename() :: String.t()

Specs

row() :: [ExPng.Color.t(), ...]

Specs

success() :: {:ok, t()}

Specs

t() :: %ExPng.Image{
  height: pos_integer(),
  pixels: ExPng.maybe(canvas()),
  raw_data: ExPng.maybe(ExPng.RawData.t()),
  width: pos_integer()
}

Link to this section Functions

Link to this function

at(image, coordinates)

See ExPng.Image.Drawing.at/2.

Link to this function

clear(image, coordinates)

See ExPng.Image.Drawing.clear/2.

Link to this function

draw(image, coordinates, color)

See ExPng.Image.Drawing.draw/3.

See ExPng.Image.Drawing.erase/1.

Link to this function

from_file(filename)

Specs

from_file(filename()) :: success() | error()

Attempts to decode a PNG file into an ExPng.Image and returns a success tuple {:ok, image} or an error tuple explaining the encountered error.

ExPng.Image.from_file("adorable_kittens.png")
{:ok, %ExPng.Image{ ... }

ExPng.Image.from_file("doesnt_exist.png")
{:error, :enoent, "doesnt_exist.png"}
Link to this function

line(image, coordinates0, coordinates1, color \\ ExPng.Color.black())

See ExPng.Image.Drawing.line/4.

Specs

new(canvas()) :: t()

Constructs a new image from the provided 2-dimensional list of pixels

Link to this function

new(width, height)

Specs

new(pos_integer(), pos_integer()) :: t()

Returns a blank (opaque white) image with the provided width and height

Link to this function

to_file(image, filename, encoding_options \\ [])

Specs

to_file(t(), filename(), ExPng.maybe(keyword())) :: {:ok, filename()}

Writes the image to disk at filename using the provided encoding_options.

Encoding options can be:

  • interlace: whether or not the image in encoding with Adam7 interlacing.
    • defaults to false
  • filter: the filtering algorithm to use. Can be one of ExPng.Image.Filtering.{none, sub, up, average, paeth}
    • defaults to up
  • compression: the compression level for the zlib compression algorithm to use. Can be an integer between 0 (no compression) and 9 (max compression)
    • defaults to 6
Link to this function

unique_pixels(image)

Specs

unique_pixels(t()) :: [ExPng.Color.t()]

Returns a list of unique pixels values used in image.