View Source Captcha (captcha v0.1.2)

Crate to generate CAPTCHAs.

Easy example:

iex> {chars, png} = Captcha.easy()
{"SnZw8", <<...>>}
iex> File.write!("captcha.png", png)
:ok

Or create by custom chars:

iex> Captcha.easy(set_color: %{r: 0, g: 116, b: 204})
{"SnZw8", <<...>>}

Create by options:

iex> Captcha.create(
...>   set_chars: "123456789abcdefgABCDEFG",
...>   add_chars: 6,
...>   set_color: %{r: 0, g: 116, b: 204},
...>   view: %{w: 220, h: 120},
...>   filters: [filter, ...]
...> )
{"78a23G", <<...>>}

Link to this section Summary

Types

supported chars: "123456789ABCDEFGHJKMNPQRSTUVWXYZabcdefghijklmnpqrstuvwxyz"

Functions

Create png image by options

Create easy image

Create hard image

Create medium image

Supported Chars

Link to this section Types

@type chars() :: String.t()

supported chars: "123456789ABCDEFGHJKMNPQRSTUVWXYZabcdefghijklmnpqrstuvwxyz"

exclude chars: 0, O, o, L, i

@type difficulty() :: :easy | :medium | :hard
@type name() :: :amelia | :lucy | :mila
@type options() :: [
  set_chars: chars(),
  add_chars: non_neg_integer(),
  set_color: %{r: non_neg_integer(), g: non_neg_integer(), b: non_neg_integer()},
  view: %{w: non_neg_integer(), h: non_neg_integer()},
  filters: [filter()]
]
@type png() :: binary()
@type return() :: {chars(), png()}

Link to this section Functions

@spec create(options()) :: return()

Create png image by options

example:

iex> Captcha.create(
...>   set_chars: "123456789abcdefgABCDEFG",
...>   add_chars: 6,
...>   set_color: %{r: 0, g: 116, b: 204},
...>   view: %{w: 220, h: 120},
...>   filters: [filter, ...]
...> )
{"SnZw8", <<...>>}
Link to this function

create_by_name(captcha_name, difficulty \\ :easy, options \\ nil)

View Source
@spec create_by_name(name(), difficulty(), options()) :: return()

Create by name

example:

iex> Captcha.create_by_name(:lucy)
{"SnZw8", <<...>>}
@spec easy(options()) :: return()

Create easy image

example:

iex> Captcha.easy()
{"SnZw8", <<...>>}
@spec hard(options()) :: return()

Create hard image

example:

iex> Captcha.hard()
{"SnZw8", <<...>>}
@spec medium(options()) :: return()

Create medium image

example:

iex> Captcha.medium()
{"SnZw8", <<...>>}
@spec supported_chars() :: binary()

Supported Chars

Not support chars: 0, O, o, L, i

example:

iex> Captcha.supported_chars()
"123456789ABCDEFGHJKMNPQRSTUVWXYZabcdefghijklmnpqrstuvwxyz"