-
Notifications
You must be signed in to change notification settings - Fork 2
Text and Media CAPTCHAs
Sepehr0Day edited this page Jun 13, 2026
·
2 revisions
Creates a distorted text image and returns the rendered answer.
from pathlib import Path
from CaptchaGenerator import CaptchaConfig, TextCaptcha
output = Path("./output")
config = CaptchaConfig(width=720, height=240, random_seed=42)
expected = TextCaptcha(config).generate(
number_gen=6,
values_captcha="ABCDEFGHJKLMNPQRSTUVWXYZ23456789",
name_export="text_captcha",
path_export=str(output),
fonts=[],
colors=["navy", "darkred", "darkgreen"],
backgrounds=[],
difficulty="medium",
style="modern",
)
print("Show image:", output / "text_captcha.png")
user_text = "ABC123"
solved = user_text.strip().casefold() == expected.casefold()
print("Solved:", solved)Available styles are modern, minimal, wave, arc and mesh.
Creates an image and a set of text choices.
from pathlib import Path
from CaptchaGenerator import CaptchaConfig, TextRandomCaptcha
output = Path("./output")
expected, choices = TextRandomCaptcha(
CaptchaConfig(width=720, height=240, random_seed=42)
).generate(
number_gen=6,
values_captcha="ABCDEFGHJKLMNPQRSTUVWXYZ23456789",
number_variants=5,
backgrounds=[],
fonts=[],
name_export="text_choices",
path_export=str(output),
difficulty="hard",
style="wave",
)
print("Show image:", output / "text_choices.png")
print("Choice buttons:", choices)
user_choice = choices[0]
solved = user_choice == expected
print("Solved:", solved)Chooses a word from a UTF-8 file containing one word per line.
from pathlib import Path
from CaptchaGenerator import CaptchaConfig, WordCaptcha
output = Path("./output")
expected = WordCaptcha(
CaptchaConfig(width=720, height=240, random_seed=42)
).generate(
backgrounds=[],
path_words="./words.txt",
fonts=[],
font_size=90,
name_export="word",
path_export=str(output),
difficulty="medium",
style="arc",
)
print("Show image:", output / "word.png")
user_word = "python"
solved = user_word.strip().casefold() == expected.casefold()
print("Solved:", solved)Example words.txt:
python
secure
captcha
verify
Removes a character from a familiar word.
from CaptchaGenerator import CaptchaConfig, MissingCharacterCaptcha
result = MissingCharacterCaptcha(
CaptchaConfig(width=720, height=240, random_seed=42)
).generate(
name_export="missing",
path_export="./output",
fonts=[],
words=("APPLE", "BANANA", "ORANGE", "PLANET"),
difficulty="medium",
style="arc",
)
print("Show image:", result.path)
print("Instruction:", result.prompt)
user_character = "P"
solved = user_character.strip().casefold() == str(result.answer).casefold()
print("Solved:", solved)Prefer word or words. Random mode is not naturally inferable unless the UI
also provides choices.
Creates an animated GIF.
from CaptchaGenerator import AnimatedCaptcha, CaptchaConfig
result = AnimatedCaptcha(
CaptchaConfig(width=720, height=240, random_seed=42)
).generate(
name_export="animated",
path_export="./output",
fonts=[],
values="ABCDEFGHJKLMNPQRSTUVWXYZ23456789",
length=6,
difficulty="hard",
style="modern",
frame_count=8,
)
print("Show GIF:", result.path)
print("Frames:", result.metadata["frame_count"])
user_text = "ABC123"
solved = user_text.strip().casefold() == str(result.answer).casefold()
print("Solved:", solved)Creates an MP3 using gTTS.
pip install "CaptchaGenerator[audio]"from CaptchaGenerator import AudioCaptcha
expected, mp3_path = AudioCaptcha().generate(
number_gen=6,
values_captcha="ABCDEFGHJKLMNPQRSTUVWXYZ23456789",
name_export="audio",
path_export="./output",
)
print("Play audio:", mp3_path)
user_text = "ABC123"
solved = user_text.strip().casefold() == expected.casefold()
print("Solved:", solved)Audio generation requires an internet connection.
- Home
- Installation
- Quick-Start
- Configuration
- Core-API
- Generator-API-Reference
- Core-Utilities
- Supported-CAPTCHAs
- All-Examples
- Text-and-Media-CAPTCHAs
- Logic-CAPTCHAs
- Image-CAPTCHAs
- Selection-CAPTCHAs
- Puzzle-CAPTCHAs
- Visual-Reasoning-CAPTCHAs
- Tkinter-Examples
- Web-Integration
- Architecture
- Creating-a-Generator
- Security
- Publishing
- Migration-to-2.0
- FAQ