Download the PHP package vaibhavpandeyvpz/ank without Composer
On this page you can find all versions of the php package vaibhavpandeyvpz/ank. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vaibhavpandeyvpz/ank
More information about vaibhavpandeyvpz/ank
Files in vaibhavpandeyvpz/ank
Package ank
Short Description Simple and customizable captcha generation library, runs on PHP >= 8.2.
License MIT
Homepage https://github.com/vaibhavpandeyvpz/ank
Informations about the package ank
Ank
A simple, customizable, and modern CAPTCHA generation library for PHP 8.2+. Generate text-based or mathematics-based CAPTCHAs with full control over appearance, fonts, colors, and distortion.
Ank (
เค เคเค) means "Number" in Hindi
Features
- ๐จ Two CAPTCHA Types: Text-based alphanumeric codes or simple math problems
- ๐ญ Highly Customizable: Colors, fonts, size, quality, and text distortion
- ๐ Secure: Uses cryptographically secure random number generation
- ๐ฏ One-Time Validation: CAPTCHA answers are automatically removed after validation
- ๐ผ๏ธ 12 Beautiful Fonts: Hand-picked Google Fonts included
- ๐ Modern PHP: Built with PHP 8.2+ features (enums, match expressions, strict types)
- ๐ฆ Zero Dependencies: Only requires PHP with GD extension
- โ Well Tested: Comprehensive test suite with high code coverage
Installation
Install via Composer:
Requirements
- PHP >= 8.2
- GD extension with FreeType support (for font rendering)
Quick Start
Basic Usage
Mathematics CAPTCHA
Advanced Usage
Customizing Appearance
The CAPTCHA image can be fully customized using a fluent interface:
Configuring Text CAPTCHA Length
Using Custom Storage
By default, CAPTCHA answers are stored in $_SESSION. You can provide a custom storage array:
Multiple CAPTCHAs
You can generate multiple CAPTCHAs with different IDs:
Available Fonts
The library includes 12 fonts from Google Fonts:
Color Formats
Colors can be specified in multiple formats:
API Reference
CaptchaGenerator
Text-based CAPTCHA generator.
Methods:
getCaptcha(string $id = 'default'): CaptchaImageInterface- Generate a new CAPTCHAisValid(string $input, string $id = 'default'): bool- Validate user inputsetLength(int $length): static- Set the length of generated codes
MathCaptchaGenerator
Mathematics-based CAPTCHA generator.
Methods:
getCaptcha(string $id = 'default'): CaptchaImageInterface- Generate a new math problemisValid(string $input, string $id = 'default'): bool- Validate the answer
CaptchaImage
CAPTCHA image object with customization methods.
Methods:
getImage(): string- Generate and return JPEG image datasetBackgroundColor(string $hex): static- Set background colorsetForegroundColor(string $hex): static- Set text colorsetFont(Font $font): static- Set fontsetSize(int $width, int $height): static- Set image dimensionssetQuality(int $quality): static- Set JPEG quality (0-100)setDistortion(int $angle, int $offset): static- Set text distortionsetText(string $text): static- Set the text to display
Error Handling
The library throws Ank\Exception\ImageGenerationException if image generation fails:
Security Considerations
- One-Time Use: CAPTCHA answers are automatically removed after validation to prevent replay attacks
- Secure Random: Uses
random_int()for cryptographically secure random number generation - Session Storage: By default uses PHP sessions, but you can provide custom storage
- Case Sensitive: Text CAPTCHAs are case-sensitive by design
Examples
Complete Form Example
AJAX Example
Testing
Run the test suite:
Or with PHPUnit directly:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Fonts are hand-picked from Google Fonts and are used in accordance with their licenses.
Author
Vaibhav Pandey
- GitHub: @vaibhavpandeyvpz
- Email: [email protected]
Changelog
See GitHub Releases for the changelog.