How to Generate Google Captcha using Python

Generate a Captcha. You can generate your own image and audio captcha using python by a third-party library called captcha.

What is Captcha?

A CAPTCHA is a test to determine whether the user is a computer or a human. CAPTCHA was developed at Carnegie Mellon University by Nicholas J. Hopper, John Langford, Luis von Ahn, and Manuel Blum.

Before getting into this we will have python and captcha packages. In this case, I will use pycharm IDE

How to install pycharm in windowshttps://iterathon.tech//how-to-install-the-pycharm-in-windows/

Open New Projects

After opening a pycharm click on a new project and you can give it any name as a captcha_generator. In this project.

Once you have give the name and click on the create. It takes few seconds to create the project, In the current project (Gmail Message) there are some existing files are found in IDE so, delete all those files using Ctrl+A and Backspace. Now Python is ready to code before that we need one awesome python packages called Captcha.

Captcha Module

A captcha library that generates audio and image CAPTCHAs.

To generate a captcha, you will need to import the captcha module or library using import method. In the Captcha library, you can use the captcha.image to generate a captcha.

Link to captcha package: https://pypi.org/project/captcha/ . After getting into the link. You need to copy the magical word to install captcha. That is pip install captcha. If you have mac then type python3 -m pip install captcha.

Again go to the pycharm and click terminal then paste the magical word pip install captcha . It takes few seconds to install packages. Once the package gets installed and then go to your project captcha_generator.

Code

This is an easy and crazy python project to generate captcha. Let’s further move on to the python program.

# Import the captcha modules
from captcha.image import ImageCaptcha

# Create an image instance of the gicen size
image = ImageCaptcha(width = 280, height = 90)

# Image captcha text
text = 'Iterathon'

# generate the image of the given text
data = image.generate(text)

# write the image on the given file and save it 
image.write(text, 'CAPTCHA.png')

After run this code, CAPTCHA.png image is save in the same location where the main.py is located. Then open a captcha.png, you can see a captcha image.

Related Post

Random Password Generator in Python: https://iterathon.tech//random-password-generator-in-python/

Difference between Data Science Vs Machine learning? : https://cybrblog.tech/difference-between-data-science-vs-machine-learning/

How to Impress a Girlfriendhttps://iterathon.tech//how-to-impress-a-girlfriend-using-python/

LEARN SOMETHING NEW 

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *