Advanced ways for generate captcha's using Python

Free Python Code - Aug 24 '23 - - Dev Community

Hi 🙂🖐

In today's post, I will share with you advanced ways to generate captchas using Python. I will use a library called captcha, and we will use advanced functions to generate captchas.

you need to install captcha from here : pip install captcha

Generate a captcha using the create_captcha_image function. With this function, you can set the text, font color, and background color.

from captcha.image import ImageCaptcha

captcha = ImageCaptcha()
captcha = captcha.create_captcha_image('123', 'red', 'white')
captcha.save('test.jpg')
Enter fullscreen mode Exit fullscreen mode

result

Image description

 Add some distance to spread pixels using the effect_spread function.


from captcha.image import ImageCaptcha


captcha = ImageCaptcha()
captcha = captcha.create_captcha_image('123', 'red', 'white')
captcha = captcha.effect_spread(6)
captcha.save('test.jpg')

Enter fullscreen mode Exit fullscreen mode

Image description

Add random curve using create_noise_curve function


captcha_image = ImageCaptcha()

image = captcha_image.generate_image('123')

captcha_image = captcha_image.create_noise_curve(image, 'red')

captcha_image.save('test.jpg')

Enter fullscreen mode Exit fullscreen mode

Image description

Add random dots using create_noise_dots function

captcha_image = ImageCaptcha()

image = captcha_image.generate_image('123')

captcha_image = captcha_image.create_noise_dots(image, 'red', 10, 30)

captcha_image.save('test.jpg')
Enter fullscreen mode Exit fullscreen mode

Image description

Rotate captcha using rotate function

from captcha.image import ImageCaptcha


captcha = ImageCaptcha()
captcha = captcha.create_captcha_image('123', 'red', 'white')
captcha = captcha.rotate(angle= 50, expand=True)
captcha.save('test.jpg')
Enter fullscreen mode Exit fullscreen mode

Image description

Now we're done 🤗

Don't forget to like and follow 🙂

Support me on PayPal 🤗
https://www.paypal.com/paypalme/amr396

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .