Utils Captcha

inyoka.utils.captcha

A module that produces image and audio captchas. Uses some code of PyCAPTCHA by Micah Dowty.

copyright:
  1. 2007-2024 by the Inyoka Team, see AUTHORS for more details.

copyright:
  1. by Micah Dowty.

license:

BSD, see LICENSE for more details.

class inyoka.utils.captcha.Captcha(solution=None)

Represents a captcha.

default_size = (300, 100)
get_response(size=None)
render_image(size=None)
class inyoka.utils.captcha.CombinedLayer(layers)

Combines multiple layers.

render(image)
class inyoka.utils.captcha.DarkBackground
class inyoka.utils.captcha.GridBackground(size=None, color=None)

Add a grid as background. You can combine this with another background layer.

bg = 'transparent'
render(image)
class inyoka.utils.captcha.Layer

Baseclass for a captcha layer.

bg = 'dark'
render(image)
class inyoka.utils.captcha.LightBackground
bg = 'light'
class inyoka.utils.captcha.NoiseBackground(saturation=0.1, num_dots=None)

Add some noise as background. You can combine this with another background layer.

bg = 'transparent'
render(image)
class inyoka.utils.captcha.Picture(picture)

Add a background to the captcha.

render(image)
class inyoka.utils.captcha.RandomBackground

Selects a random background.

class inyoka.utils.captcha.RandomDistortion

Selects a random distortion.

background = 'transparent'
class inyoka.utils.captcha.SineWarp(amplitude_range=(3, 6.5), period_range=(0.04, 0.1))

Warp the image using a random composition of sine waves

get_transform(image)

Return a transformation function, subclasses should override this

class inyoka.utils.captcha.SolidColor(color=None)

A solid color background. Very weak on its own, but good to combine with other backgrounds.

render(image)
class inyoka.utils.captcha.TextLayer(text, min_size=32, max_size=48, bg='dark')

Add text to the captcha.

bg = 'transparent'
render(image)
class inyoka.utils.captcha.WarpBase

Abstract base class for image warping. Subclasses define a function that maps points in the output image to points in the input image. This warping engine runs a grid of points through this transform and uses PIL’s mesh transform to warp the image.

bg = 'transparent'
filtering = 2
get_transform(image)

Return a transformation function, subclasses should override this

render(image)
resolution = 10
class inyoka.utils.captcha.WigglyBlocks(block_size=None, sigma=0.01, iterations=None)

Randomly select and shift blocks of the image

bg = 'transparent'
render(image)
inyoka.utils.captcha.generate_word()

This function returns a pronounceable word.

inyoka.utils.captcha.get_random_resource(type, prefix=None)

Return a random resource of a given type.

inyoka.utils.captcha.random_color(saturation=0.5, lumination=None)

Return a random number with the given saturation.