Thumbp (ThumbP v0.2.1)

Copy Markdown View Source

A Lightweight & Fast WebP Thumbnail Image Generator

Summary

Functions

Create a thumbnail image.

Create a thumbnail image with options.

Types

body()

@type body() :: binary()

height()

@type height() :: 1..16383

width()

@type width() :: 1..16383

Functions

create(body, width, height)

@spec create(body(), width(), height()) :: {:ok, binary()} | {:error, String.t()}

Create a thumbnail image.

width and height must be integers between 1 and 16383, the maximum dimension the WebP format can represent.

Examples

iex> content = File.read!("./test/assets/images/sample.jpg")
iex> Thumbp.create(content, 320, 240)
{:ok, <<82, 73, 70, 70, 102, 12, 0, 0, 87, 69, 66, 80, ...>>}

create(body, width, height, opts)

@spec create(body(), width(), height(), keyword()) ::
  {:ok, binary()} | {:error, String.t()}

Create a thumbnail image with options.

Options

  • quality - Quality value from 0 to 100. Defaults to 60.
  • target_size - Target size in bytes. Increases processing time by approximately 20-80%.
  • effort - Encoding effort from 0 (fastest) to 6 (smallest file size). Defaults to 3.

The quality and target_size options are mutually exclusive.

Examples

iex> content = File.read!("./test/assets/images/sample.jpg")
iex> Thumbp.create(content, 320, 240, quality: 50)
iex> Thumbp.create(content, 320, 240, target_size: 12_000)
iex> Thumbp.create(content, 320, 240, effort: 5)