diff --git a/docs/changelog.rst b/docs/changelog.rst index b22d689..f817168 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -7,6 +7,12 @@ Changelog ---- +v0.6.0 +------ + +Released on Jul 18, 2024 + +- Add character settings for ``ImageCaptcha``. v0.5.0 ------ diff --git a/docs/image.rst b/docs/image.rst index 956d928..3fdb899 100644 --- a/docs/image.rst +++ b/docs/image.rst @@ -68,3 +68,30 @@ specific endpoint. code = "ABCD" data = image.generate(code) return Response(data, mimetype="image/png") + +Character Settings +------------------ + +.. versionadded:: 0.6 + +Update the default settings to change the character renderring. + +.. code-block:: python + + from captcha.image import ImageCaptcha + + captcha = ImageCaptcha() + captcha.character_rotate = (-40, 40) + captcha.generate("ABCD") + +Available options: + +.. code-block:: python + + character_offset_dx: tuple[int, int] = (0, 4) + character_offset_dy: tuple[int, int] = (0, 6) + character_rotate: tuple[int, int] = (-30, 30) + character_warp_dx: tuple[float, float] = (0.1, 0.3) + character_warp_dy: tuple[float, float] = (0.2, 0.3) + word_space_probability: float = 0.5 + word_offset_dx: float = 0.25 diff --git a/src/captcha/__init__.py b/src/captcha/__init__.py index d62cd39..5d2033d 100644 --- a/src/captcha/__init__.py +++ b/src/captcha/__init__.py @@ -10,6 +10,6 @@ :license: BSD, see LICENSE for more details. """ -__version__ = '0.5.0' +__version__ = '0.6.0' __author__ = 'Hsiaoming Yang ' __homepage__ = 'https://github.com/lepture/captcha' diff --git a/src/captcha/image.py b/src/captcha/image.py index 69cdbad..773aa44 100644 --- a/src/captcha/image.py +++ b/src/captcha/image.py @@ -48,7 +48,7 @@ class ImageCaptcha: lookup_table: list[int] = [int(i * 1.97) for i in range(256)] character_offset_dx: tuple[int, int] = (0, 4) character_offset_dy: tuple[int, int] = (0, 6) - chracter_rotate: tuple[int, int] = (-30, 30) + character_rotate: tuple[int, int] = (-30, 30) character_warp_dx: tuple[float, float] = (0.1, 0.3) character_warp_dy: tuple[float, float] = (0.2, 0.3) word_space_probability: float = 0.5 @@ -121,7 +121,7 @@ def _draw_character( # rotate im = im.crop(im.getbbox()) im = im.rotate( - random.uniform(*self.chracter_rotate), + random.uniform(*self.character_rotate), BILINEAR, expand=True, )