Skip to content

Text and Media CAPTCHAs

Sepehr0Day edited this page Jun 13, 2026 · 2 revisions

Text and Media CAPTCHAs

TextCaptcha

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.

TextRandomCaptcha

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)

WordCaptcha

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

MissingCharacterCaptcha

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.

AnimatedCaptcha

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)

AudioCaptcha

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.

Clone this wiki locally