Image.Plug.Pipeline (image_plug v0.1.0)

Copy Markdown View Source

The canonical, provider-neutral image-processing pipeline.

A pipeline is an ordered list of typed operation structs (under Image.Plug.Pipeline.Ops.*) plus pipeline-wide settings: the output format, an error policy, and a debug breadcrumb identifying the provider that produced it.

Pipelines are pure data. Behaviour lives in Image.Plug.Pipeline.Interpreter (executes ops), Image.Plug.Pipeline.Encoder (serialises the result), and Image.Plug.Pipeline.Normaliser (reorders, folds, validates).

Summary

Functions

Appends an operation to a pipeline.

Builds a new, empty pipeline.

Replaces the pipeline's output (Ops.Format) struct.

Types

on_error()

@type on_error() ::
  :auto
  | :render_error_image
  | :fallback_to_source
  | :raise
  | {:status, 100..599}

op()

t()

@type t() :: %Image.Plug.Pipeline{
  on_error: on_error(),
  ops: [op()],
  output: Image.Plug.Pipeline.Ops.Format.t(),
  provider: nil | module()
}

Functions

append(pipeline, op)

@spec append(t(), op()) :: t()

Appends an operation to a pipeline.

Arguments

  • pipeline is an Image.Plug.Pipeline struct.

  • op is any operation struct under Image.Plug.Pipeline.Ops.*.

Returns

  • The pipeline with op appended to :ops.

Examples

iex> alias Image.Plug.Pipeline
iex> alias Image.Plug.Pipeline.Ops.Rotate
iex> p = Pipeline.append(Pipeline.new(), %Rotate{angle: 90})
iex> length(p.ops)
1

new(options \\ [])

@spec new(keyword()) :: t()

Builds a new, empty pipeline.

Options

  • :output is an Image.Plug.Pipeline.Ops.Format struct describing the encoder configuration. Defaults to %Ops.Format{} (auto format, quality 85, copyright-only metadata).

  • :on_error is the error policy. Defaults to :auto — see Image.Plug for selection semantics.

  • :provider is an optional debug breadcrumb identifying the provider module that produced the pipeline.

Returns

Examples

iex> p = Image.Plug.Pipeline.new()
iex> p.ops
[]
iex> p.output.type
:auto

put_output(pipeline, format)

@spec put_output(t(), Image.Plug.Pipeline.Ops.Format.t()) :: t()

Replaces the pipeline's output (Ops.Format) struct.

Arguments

Returns

  • The pipeline with :output replaced.

Examples

iex> alias Image.Plug.Pipeline
iex> alias Image.Plug.Pipeline.Ops.Format
iex> p = Pipeline.put_output(Pipeline.new(), %Format{type: :webp, quality: 80})
iex> p.output.type
:webp