YaxinLuo's picture
Upload 3038 files
1fcfb5f verified

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:

  1. Taking source images from the sources/ directory
  2. Randomly selecting one image
  3. Splitting it into a grid (2x2 or 3x3 pieces)
  4. Creating puzzle pieces that users must drag to complete

Setup

  1. Install Pillow (if not already installed):

    pip install pillow
    # or
    uv add pillow
    
  2. Add 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

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

  1. Add images to sources/ directory
  2. The system will automatically generate puzzles using these images
  3. Each puzzle request creates a new random puzzle
  4. Pieces are shuffled and presented to the user
  5. 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).