View Source Thumbp (ThumbP v0.1.4)
A Fastest WebP image thumbnail creator for Elixir.
Summary
Types
@type body() :: binary()
@type height() :: pos_integer()
@type quality() :: float() | non_neg_integer()
@type target_size() :: pos_integer()
@type width() :: pos_integer()
Functions
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, ...>>}
@spec create(body(), width(), height(), [{:quality, quality()}]) :: {:ok, binary()} | {:error, String.t()}
@spec create(body(), width(), height(), [{:target_size, target_size()}]) :: {:ok, binary()} | {:error, String.t()}
@spec create(body(), width(), height(), quality: quality(), target_size: target_size()) :: {:error, String.t()}
@spec create(body(), width(), height(), list()) :: {: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)