Skip to main content

A simple CAPTCHA image generator

Project description

A simple CAPTCHA image generator.

This module provides a single class (Claptcha) that can create on the fly PIL Image instances, BytesIO objects or save image files containing a simple CAPTCHA strings. Its build on top of Pillow package.

It is required that user provides a TTF file with font to be used in images and either a string with CAPTCHA text or a callable object returning strings to be used in images.


>>> from claptcha import Claptcha
>>> # Initialize Claptcha object
>>> c = Claptcha("Text", "FreeMono.ttf")
>>> # Create a PIL Image object, return it and provided text
>>> c.image
('Text', <PIL.Image.Image image mode=RGB size=200x80 at 0xB741406C>)
>>> # Create a BytesIO object, return it and provided text
>>> c.bytes
('Text', <_io.BytesIO object at 0xb71e87dc>)
>>> # Save image in 'claptcha.png' file, return its path and provided text
>>> c.write('claptcha.png')
('Text', 'test.png')
>>> def captchaStr():
...     return "TextFromFunc"
>>> # Redefine c: change its size to 100x30, use bicubic resampling filter
>>> # and add white noise
>>> from PIL import Image
>>> c = Claptcha(captchaStr, "FreeMono.ttf", (100,30),
...              resampling=Image.BICUBIC, noise=0.3)
>>> c.image
('TextFromFunc', <PIL.Image.Image image mode=RGB size=100x30 at 0xB73EE66C>)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for claptcha, version 0.3.3
Filename, size File type Python version Upload date Hashes
Filename, size claptcha-0.3.3-py3-none-any.whl (7.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size claptcha-0.3.3.tar.gz (5.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page