View Source Thumbp (ThumbP v0.1.5)

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() :: pos_integer()

quality()

@type quality() :: float() | non_neg_integer() | nil

target_size()

@type target_size() :: pos_integer() | nil

width()

@type width() :: pos_integer()

Functions

create(body, width, height)

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

Create a thumbnail image

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(), list()) ::
  {:ok, binary()} | {:error, String.t()}

Create a thumbnail image with options

Quality

The quality ranges from 0 to 100, defaulting to 75.

Target size

You can also specify a target size in bytes, although this will increase the processing time by approximately 20% to 80%.

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)