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')
result
Β 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')
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')
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')
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')
Now we're done π€
Don't forget to like and follow π
Support me on PayPal π€
https://www.paypal.com/paypalme/amr396