Jigsaw Puzzle CAPTCHA Generator
This directory contains the Jigsaw Puzzle CAPTCHA implementation with automatic puzzle generation.
How It Works
The Jigsaw Puzzle CAPTCHA can generate unlimited random puzzles by:
- Taking source images from the
sources/directory - Randomly selecting one image
- Splitting it into a grid (2x2 or 3x3 pieces)
- Creating puzzle pieces that users must drag to complete
Setup
Install Pillow (if not already installed):
pip install pillow # or uv add pillowAdd Source Images:
- Place any images (PNG, JPG, JPEG) in the
sources/directory - The generator will automatically use these images
- Recommended: Use images that are visually distinct and easy to recognize
- Images will be automatically resized to fit the puzzle grid
- Place any images (PNG, JPG, JPEG) in the
Configuration
Edit ground_truth.json to configure the generator:
{
"config": {
"generate_random": true, // Enable random generation
"source_images_dir": "captcha_data/Static_Jigsaw/sources",
"grid_rows": 2, // 2 or 3 (rows in grid)
"grid_cols": 2, // 2 or 3 (columns in grid)
"piece_size": 150 // Size of each piece in pixels
}
}
Features
- Infinite Puzzles: Each request generates a new unique puzzle
- Easy for Humans: Small grid sizes (2x2 or 3x3) make it easy to solve
- Random Source Selection: Randomly picks from available source images
- Automatic Sizing: Images are automatically resized to fit the grid
- Base64 Encoding: Pieces are embedded as data URLs (no file storage needed)
- Reference Image: Shows the complete image as a hint
Grid Sizes
- 2x2: 4 pieces (easiest)
- 3x3: 9 pieces (medium difficulty)
- Maximum is 3x3 to keep it easy for humans
Example Usage
- Add images to
sources/directory - The system will automatically generate puzzles using these images
- Each puzzle request creates a new random puzzle
- Pieces are shuffled and presented to the user
- User drags pieces to complete the puzzle
Fallback
If generation fails or generate_random is false, the system falls back to using predefined puzzles from ground_truth.json (like jigsaw0).