# 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](https://github.com/huacnlee/rucaptcha)
Based on the repo here: https://github.com/davidqhr/elixir-captcha
<img src="https://cloud.githubusercontent.com/assets/5518/22151425/e02390c8-df58-11e6-974d-5eb9b1a4e577.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151427/e4939d92-df58-11e6-9754-4a46a86acea8.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151431/e494576e-df58-11e6-9845-a5590904c175.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151432/e495066e-df58-11e6-92b8-38b40b73aba0.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151428/e49404ee-df58-11e6-8e2d-8b17b33a3710.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151430/e4942406-df58-11e6-9ff8-6e2325304b41.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151429/e4941ae2-df58-11e6-8107-757296573b2f.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151433/e4c7c89c-df58-11e6-9853-1ffbb4986962.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151435/e4c97ea8-df58-11e6-8959-b4c78716271d.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151436/e4cc09f2-df58-11e6-965c-673333b33c0d.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151434/e4c87788-df58-11e6-9490-c255aaafce71.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151445/ee35ff66-df58-11e6-8660-a3673ef3f5ee.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151446/ee67b074-df58-11e6-9b95-7d53eec21c33.gif" width="150px" />
## Production Reliability
This version includes critical fixes for production environments:
- **Fixed intermittent empty image generation** in production deployments
- **Replaced Port.open with System.cmd** for better reliability
- **Added robust parsing** with GIF header detection
- **Enhanced error handling** with detailed error messages
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`:
```elixir
def deps do
[{:captcha_c, "~> 0.1.0"}]
end
```
## Usage
```elixir
# 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
```