Python/Python ETC
Python captcha : Python으로 사람확인문자 만들기. Python captcha. Python으로 captcha 이미지 만들기
CosmosProject
2021. 10. 31. 19:09
728x90
반응형
회원가입을 할 때 보면 정보를 다 입력하고 마지막 부분에 이상하게 생긴 문자들을 입력하라고 하는것이 보통입니다.
위 이미지처럼요.
위와같은 것을 주로 Captcha라고 하는데 이번에는 Python으로 위 이미지처럼 특정 문자를 captcha로 만들어보겠습니다.
pip install captcha
먼저 captcha library를 설치해줍니다.
from captcha.image import ImageCaptcha
image = ImageCaptcha(width=160, height=90)
txt_captcha = '3ck8Bei'
image.generate(txt_captcha)
image.write(txt_captcha, 'captcha_result.png')
위 코드를 실행해보면 아래처럼 내가 원하는 문자가 captcha가 생성됩니다.
이제 위 코드를 하나씩 알아봅시다.
image = ImageCaptcha(width=160, height=90)
import한 ImageCaptcha에 먼저 생성할 captcha의 이미지 크기를 지정합니다.
저는 가로 160, 세로 90으로 했습니다.
txt_captcha = '3ck8Bei'
captcha로 만들 문자를 지정해줍니다.
image.generate(txt_captcha)
지정한 문자를 captcha로 생성(generate)합니다.
image.write(txt_captcha, 'captcha_result.png')
생성된 captcha image를 저장합니다.
728x90
반응형