util-captcha 0.2.2
A library that generates image CAPTCHAs.
License: MIT
Requires Python: >=3.9,<4.0
Keywords: util,captcha

# util-captcha

- Captcha with default

  ![](https://gitee.com/full-stack-web/util-captcha/raw/master/examples/captcha-default.png)

- Captcha with Noise dots

  ![](https://gitee.com/full-stack-web/util-captcha/raw/master/examples/captcha-noise_dots.png)

- Captcha with space evenly

  ![](https://gitee.com/full-stack-web/util-captcha/raw/master/examples/captcha-space_evenly-True.png)

  ![](https://gitee.com/full-stack-web/util-captcha/raw/master/examples/captcha-space_evenly-False.png)

- Base64 data

  <details>
    <summary>View</summary>

  data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAAoCAYAAAA16j4lAAAX6UlEQVR4nO17eZSdVZXvb+/zTXeoebhVlaEyk4GEzMxJA0FakSFi5CmiIA20LhVt7eXTXr4063Wz7NX6BBa8pUirKC5RGmkxDDaDDYQACZCQQCBJpUKlKknNVbfqTt/3nXP2+6MCJpBUqkJ40C5+/9S6t+63zz57PnufjwBMxYf4iwW/3wx8iPcWHyr4LxwfKvjdg6qBOAD0+83IkeC83wz8NwcDyL64sjn37IA7p871+lIucqs37y7vCkN6v5kDAMJfaJH1PaD/AEC3ANUA5L1YY04Q2DtnzSq2S7zAY7oIsFMY1Katc/Mnt23TANR7se548EFQsODrG7pOHSqU22hIb/rTVwUdHZU4fqXQDUA/nzIxBQBbezpKj+9HxbugdzRED82YQHF5xZXW4FxLtjzJTnVsbCE0spOIHr1m2/bHsu+RcY0Voyk43LjiiksnJ8oqhyTq9IVt3vDWuU/cMXCCeZB048nBnAv+5etK+Bwr4QO7Xvz1LQOv/kYd5G88sFfPmdBQ6flzI2Ma2ALkYJoBPzKtP/7TXR0dzlYgjXcvdDmjrMz/h+mTzy5auVSRNAhJAaCCNXag1gsWZU3cAiU/2Rm7j/391q2ZE7DmceFIOVjOqJkUPX7aZXfmYr0zr0unNwSp5QNhcYNPev2Gs6586Iz1v3wDJ65Ak0S6MWArq0ipJMGfN/Osa8s2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Mgl/bLy0M90BciHBf9MQ/sl67/1dALZ12520A3usTLDaTWitQzKCEkKRFB2vUCIyLG6FZt+T6MvcVGAEzlwvOfZ0OPMNyLtQlLhULPcV83/fHLHe6Plyx5/cWBge8Pt7a6v8ZhFXz64N+Rzz5YrJnFzAIQIKCgKjCJmTyY3ZhNoYhxH0/GjgElTl0/rAyJgFncbFbyPYVSZxIAuTyQT3PNAJiK4YgHjytMj1nBQ2Fol63/5XeeO+uKM1ip/5NU7tKEo9hVrviOTwdyAwVrxFjYrcbw6khJHcZ5fSbdON8WWrc8NbIH99BJzfEIl65/8cXMIZ9HpcFMrogoEoAgZSpAYzTIQdnM2ni4LuzDM8NJlN6bd7kO5HaGDcmZ+yAohHFpXyFqe3PIQHFoQvJoTzbsHjqeImtcCsiGodGRfcqH80cmcGxsXIpK+/JRcTgTpF/SYv7OJzXJOtw80FloGwdpAeA/eePUxk2/XL01HN7X7vipJvx/vDAuRAGx8sEciNAUAhY5Sp3BnjqzYih5UcXJ9e57xc8CLMizVi1aD77RG7Uefk0pAfQN7zmQi/qPNoodFeN+NynjV8jGFZfPV0Srar3k7mxc9G9r2/xEXSrIf2XyomzVwz/yrm1e3P+vOzbUjpeZ9w0+VPm8ujVK0UQicq0FEUkkIiHAAoGFFZBjN4GRM5pjAmkp6dzQq33d+AC/hvtBePnsA4GyZbUuG7fMSarz2OfTdD4aFCMxBEREDAAjPWzbxUDRWgmJYJmc/QL7OigWC7eQ3Za1+IC8Ogp8qODD4fuoPqU2A5LZJoxzTtJZAMUzCXJo2JS4oIcYMIBYCyaI3Uew+x2m7b2v9Pa+V7n6ePChgkeHLp9XPYcTTj3JwTMxkRCQIF+dTwc7dQIoq81OkviR/Mv5zvBDD/5vD3EzbjrVXLkIQhYACFwmgtcGt3W2ITxxbya8W3yo4L9w/D87wfk7vuSBqAAAAABJRU5ErkJggg==

  </details>

## Introduction

A library that generates image CAPTCHAs.

## Installation

```bash
pip install util-captcha
```

## Usage

```py
from util_captcha import ImageCaptcha

image_captcha = ImageCaptcha()

# generate default captcha
image_captcha.draw_chars()
image_captcha.draw_noise_curve()
image_captcha.draw_noise_dots()
image_captcha.canvas.save("./examples/captcha-default.png")

# generate captcha of only noise dots
image_captcha.redraw()  # redraw canvas (required)
image_captcha.draw_chars()
image_captcha.draw_noise_dots(333)
image_captcha.canvas.save("./examples/captcha-noise_dots.png")

# generate captcha by space evenly
image_captcha.redraw()  # redraw canvas (required)
image_captcha.draw_chars("abc", space_evenly=True)
image_captcha.canvas.save("./examples/captcha-space_evenly-True.png")
image_captcha.redraw()  # redraw canvas (required)
image_captcha.draw_chars("abc", space_evenly=False)
image_captcha.canvas.save("./examples/captcha-space_evenly-False.png")

# use base64 data to generate captcha
image_captcha.redraw()  # redraw canvas (required)
image_captcha.draw_chars("base64")
data = image_captcha.generate_base64()
print(data)
```