Examples - MagicaFreak/captchas GitHub Wiki

Basic Captcha

The basic captcha without any settings

def test_basic_captcha():
    captcha = CaptchaImage()
    captcha.create()
    captcha.image.save(f'../example/basic.png', format='PNG')

Custom Color

The captcha with a custom color

def test_color_captcha():
    captcha = CaptchaImage(color=(255, 0, 0))
    captcha.create()
    captcha.image.save(f'../example/color.png', format='PNG')

Custom Text

The captcha with predefined text

def test_text_captcha():
    captcha = CaptchaImage(text="MagicaFreak")
    captcha.create()
    captcha.image.save(f'../example/text.png', format='PNG')

Generated Text

The captcha with a generated text with predefined length

def test_generated_text_captcha():
    captcha = CaptchaImage(char_amount=6)
    captcha.create()
    captcha.image.save(f'../example/chars.png', format='PNG')

Background RANDOM

The captcha with the background setting RANDOM

def test_background_random_captcha():
    captcha = CaptchaImage(background=Background.RANDOM)
    captcha.create()
    captcha.image.save(f'../example/bg_random.png', format='PNG')

Background COLOR

The captcha with the background setting COLOR

def test_background_color_captcha():
    captcha = CaptchaImage(background=Background.COLOR)
    captcha.create()
    captcha.image.save(f'../example/bg_color.png', format='PNG')

Background COLOR and custom color

The captcha with the background setting COLOR and a custom color

def test_background_custom_color_captcha():
    captcha = CaptchaImage(background=Background.COLOR, color=(128, 0, 64))
    captcha.create()
    captcha.image.save(f'../example/bg_custom_color.png', format='PNG')

Distortion

The captcha with the distortion setting

def test_distortion_captcha():
    captcha = CaptchaImage(distortion=True, font_size=50)
    captcha.create()
    captcha.image.save(f'../example/distortion.png', format='PNG')

Lines

The captcha with random lines

def test_lines_captcha():
    captcha = CaptchaImage(lines=4)
    captcha.create()
    captcha.image.save(f'../example/lines.png', format='PNG')

Points

The captcha with random Points

def test_points_captcha():
    captcha = CaptchaImage(points=4)
    captcha.create()
    captcha.image.save(f'../example/points.png', format='PNG')

Frame

The captcha with a frame around it

def test_frame_captcha():
    captcha = CaptchaImage(frame=True)
    captcha.create()
    captcha.image.save(f'../example/frame.png', format='PNG')

Every Setting

The captcha with every setting turned on.(Without Overwrites)

def test_everything_captcha():
    captcha = CaptchaImage(font_size=50, color=(255, 0, 128), text="MagicaFreak",
                           background=Background.RANDOM, distortion=True, lines=10,
                           points=15, frame=True)
    captcha.create()
    captcha.image.save(f'../example/everything.png', format='PNG')

Overwrite Distortion

The captcha with an overwritten distortion function and distortion factor

def test_overwrite_distortion_captcha():
    captcha = CaptchaImage(distortion=True)
    captcha.distortion = lambda x, a, w: a * cos(5 * pi * x * w + 400)
    captcha.create()
    captcha.image.save(f'../example/overwrite_distortion.png', format='PNG')

    captcha.distortion_factor = (0.5, 16)
    captcha.create()
    captcha.image.save(f'../example/overwrite_distortion_factor.png', format='PNG')

Overwrite Background RANDOM Colors

The captcha with overwritten colors for background RANDOM

def test_overwrite_random_colors_captcha():
    captcha = CaptchaImage(background=Background.RANDOM)
    captcha.colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]
    captcha.create()
    captcha.image.save(f'../example/overwrite_bg_random.png', format='PNG')