Skip to main content

Generate once-off "CAPTCHA"-type images and audio files from the command line.

Project description

PyCAPTCHAGen is a very basic command line utility for generating once-off “CAPTCHA”-type image and audio files to help deter abuse by bots on the web. Normally, these distorted text and audio challenges are generated dynamically and automatically on-the-fly for each request. However, this can be somewhat complicated to implement, and many off-the-shelf solutions rely on third-party services that some of us would prefer not to deal with. Say you’re just managing a simple, low-traffic site and have a contact form or email address that you want to hide from casual scraping by spam bots (the author’s original use case). In this case, just generating a single “CAPTCHA”-style challenge is easier to implement and may be reasonably effective, depending on your needs.

Basic usage:

pycaptchagen 'text to garble' outputname

At this time, the only supported image format is PNG with a resolution of 160 x 60 pixels. A “.png” file extension is appended automatically to the output name you provide. Note that it is advisable to enclose your text input in quote marks, and you must do so if it contains spaces or characters that are treated specially by your shell.

To also generate an audio file for accessibility by visually impaired users:

pycaptchagen --audio 'text to garble' outputname

At this time, the only supported audio format is WAV (mono, 8-bit, 8 kHz = 64 kbps). The same output name is used for the image and audio files, and a “.wav” file extension is automatically appended for the audio file.

If you want just the audio file without a matching image:

pycaptchagen --audio --noimage 'text to garble' outputname

You can use the default font and voice, or you may specify others of your choosing as follows:

pycaptchagen --font /path/to/font.ttf --voicedir /path/to/voicedata 'text to garble' outputname

The font can be any TrueType font, as long as it includes all the characters used in your input. You may also specify multiple fonts by invoking the --font option multiple times, and the image generator will use a random mix of the different fonts for different characters.

The voice data directory you specify must contain a subdirectory with the name of each character, with each of these subdirectories containing a single 8-bit, 8 kHz mono WAV file (with a .wav file extension) for that character. See the Python captcha library source code for an example. At the time of this writing, the default voice data only contains the numerals 0-9, so unless your input is just a non-negative integer, you will get an error without specifying your own voice directory. This may (hopefully) be fixed in a future version of the captcha library.

License

PyCAPTCHAGen is public domain software available under The Unlicense. Feel free to use, study, share, and modify the code as you see fit. :)

Acknowledgements

PyCAPTCHAGen uses Hsiaoming Yang’s Python captcha library.

Project details


Download files

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

Source Distribution

pycaptchagen-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycaptchagen-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file pycaptchagen-0.1.0.tar.gz.

File metadata

  • Download URL: pycaptchagen-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for pycaptchagen-0.1.0.tar.gz
Algorithm Hash digest
SHA256 184f522b03ca47e06a5aeaf305f5fc5c19079e53feb8743054d3f6bbdc1f9116
MD5 2712e30ea0dc6e484dcc96633c382ff9
BLAKE2b-256 9b7a2b541c1f79427fc16fce61ee55fe778f4be95c040ca13b959ac9eba840ce

See more details on using hashes here.

File details

Details for the file pycaptchagen-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pycaptchagen-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for pycaptchagen-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33c20aba90dc667eb579ef4e41f2c3f6fc023bfdfa434b3e2abb98ff2877e57c
MD5 6b1652f3c5b11459def1aa5cf2ab904e
BLAKE2b-256 8c2f79e8a05acf163fc5e3a0166cb2a2cafe3276638cd5bee2ba9dde2df97440

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page