Gregwar Captcha
Generate distorted CAPTCHA images in PHP to stop bots.
Repository Health
Technical Analysis
Gregwar Captcha is a PHP library for generating CAPTCHA images that help protect forms from bots and spam. A fluent CaptchaBuilder produces a random phrase and renders it as a distorted image you can save to disk, stream to the browser, or inline as a data URI.
The builder is highly configurable — you control the phrase, fonts, colors, distortion, background, and image quality — and it pairs a PhraseBuilder for generating and validating the challenge text against user input.
What You Get
- A fluent
CaptchaBuilderfor generating CAPTCHA images - Save-to-file, direct output, and inline data-URI rendering
- Configurable phrase, fonts, colors, distortion, and quality
- A
PhraseBuilderfor creating and validating challenge text
Common Use Cases
- Protecting registration and contact forms from automated bots
- Reducing comment and signup spam on PHP websites
- Rendering inline CAPTCHA images without writing temporary files
Under The Hood
Architecture - CaptchaBuilder (implementing CaptchaBuilderInterface) holds a phrase from PhraseBuilder, then in build() uses PHP’s GD extension to create an image, draw the phrase with bundled TTF fonts, and apply distortions (wave interpolation, random lines, background noise). Output methods save(), get(), output(), and inline() encode the GD resource to JPEG. Tech Stack - PHP with the GD image extension, bundled font files, distributed via Composer under the Gregwar\Captcha namespace; tests run under PHPUnit. Code Quality - Mature and widely adopted (1.8k stars, active releases) with a small focused class set and interface abstraction; test coverage is present though modest. API Design - Very approachable: (new CaptchaBuilder)->build() yields a captcha, and chainable setters plus three output modes keep integration to a few lines.