[python] Generate Captcha Using Python
https://www.geeksforgeeks.org/generate-captcha-using-python/
In this article, we are going to see how to generate a captcha using Python package captcha to generate our own CAPTCHA (Completely Automated Public Turing Test to Tell Computers and Humans Apart) in picture form. CAPTCHA is a form of challenge-response authentication security mechanism. CAPTCHA prevents automated systems from reading the distorted characters in the picture.
Installation:
pip install captcha
Generating image captcha:
Here we are going to generate an image captcha:
Stepwise implementation:
Step 1: Import module and create an instance of ImageCaptcha().
image = ImageCaptcha(width = 280, height = 90)
Step 2: Create image object with image.generate(CAPTCHA_Text).
data = image.generate(captcha_text)
Step 3: Save the image to a file image.write().
image.write(captcha_text, 'CAPTCHA.png')
Below is the full implementation:
- Python3
# Import the following modules
from captcha.image import ImageCaptcha
# Create an image instance of the given size
image = ImageCaptcha(width = 280, height = 90)
# Image captcha text
captcha_text = 'GeeksforGeeks'
# generate the image of the given text
data = image.generate(captcha_text)
# write the image on the given file and save it
image.write(captcha_text, 'CAPTCHA.png')
|
Output:
Image CAPTCHA
Generating Audio captcha:
Here we are going to generate an audio captcha:
Stepwise implementation:
Step 1: Import module and create an instance of AudioCaptcha().
image = audioCaptcha(width = 280, height = 90)
Step 2: Create an audio object with audio.generate(CAPTCHA_Text).
data = audio.generate(captcha_text)
Step 3: Save the image to file audio.write().
audio.write(captcha_text, audio_file)
Below is the full implementation:
- Python3
# Import the following modules
from captcha.audio import AudioCaptcha
# Create an audio instance
audio = AudioCaptcha()
# Audio captcha text
captcha_text = "5454"
# generate the audio of the given text
audio_data = audio.generate(captcha_text)
# Give the name of the audio file
audio_file = "audio"+captcha_text+'.wav'
# Finally write the audio file and save it
audio.write(captcha_text, audio_file)
|
Output:
Ready to dive into the future? Mastering Generative AI and ChatGPT is your gateway to the cutting-edge world of AI. Perfect for tech enthusiasts, this course will teach you how to leverage Generative AI and ChatGPT with hands-on, practical lessons. Transform your skills and create innovative AI applications that stand out. Don't miss out on becoming an AI expert – Enroll now and start shaping the future!
'프로그래밍 > Python' 카테고리의 다른 글
[python]Simple Python Version Management: pyenv (1) | 2024.09.26 |
---|---|
[python] 랜덤 6자리 문자열을 생성하고, 중복되지 않도록 파일명을 지정한 후 이미지 캡차를 저장. captcha (0) | 2024.09.25 |
[python] IPython 설치, Math, Sympy (1) | 2024.09.10 |
[python] 2차 방정식 (0) | 2024.09.10 |
[python] html table을 Markdown으로 변경하기. (0) | 2024.09.04 |