This Python script generates a customizable CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) image with randomly colored characters and different fonts >ᴗ< .
- Python (3.x recommended) 🐍
- Python Imaging Library (PIL) or Pillow 🖼️
-
Clone the repository or download the
captcha.pyfile. -
Install the required Python libraries using pip:
pip install Pillow
-
Ensure you have TTF font files in the specified paths (e.g.,
arial.ttf,times.ttf,calibri.ttf). You can replace these paths with your own font files.
-
Modify the
generate_captcha()function incaptcha.pyto suit your preferences, such as text length, image dimensions, and font paths. -
Run the script using the command:
python captcha.py
-
The script will generate a CAPTCHA image (
captcha.png) with random characters, colors, and fonts. The generated text will be printed in the terminal.
-
Adjust the
text_length,image_width, andimage_heightparameters ingenerate_captcha()to change the length and size of the CAPTCHA. -
Add or remove font paths in the
font_pathslist to use different fonts for the CAPTCHA characters. -
Modify the color generation logic or font sizes to suit your preferences by updating the code within the
generate_captcha()function.
-
Ensure the font files exist in the specified paths. Update the font paths in the code to reflect the actual locations of your font files.
-
This code provides a basic personal example of CAPTCHA generation.