Captcha

This is a Elixir lib for generating captcha. No dependencies. It drawing captcha image with C code. No ImageMagick, No RMagick.

C code come from: https://github.com/huacnlee/rucaptcha

Based on the repo here: https://github.com/davidqhr/elixir-captcha

Production Reliability

This version includes critical fixes for production environments:

The original library would sometimes return only 5 bytes (text) instead of the full 17,651 bytes (text + image) in production environments due to process management differences between development and production.

Requirements

Requires a C compiler and make (pre-installed on macOS and most Linux distributions).

Installation

Add captcha_c to your list of dependencies in mix.exs:

def deps do
[{:captcha_c, "~> 0.1.0"}]
end

Docker

When building a release in Docker, the compiled captcha binary may not be copied into the release automatically. You may need to manually copy it:

RUN mkdir -p _build/prod/lib/captcha_c/priv && \
cp deps/captcha_c/priv/captcha _build/prod/lib/captcha_c/priv/captcha

Usage

# Basic usage
case Captcha.get() do
{:ok, text, img_binary} ->
# save text in session, then send img to client
{:error, reason} ->
# handle specific error
end