음.... 추석날 파이선을 어떻게 하면서 만들어 본것.. orz

 

captcha.py

 

 

 

#!/usr/bin/python

import Image
import ImageDraw
import ImageFont
import ImageFilter
import ImageOps
import random

import sys
import string
from optparse import OptionParser
global ext
ext = ".jpg"

makeCnt = int(sys.argv[1])
 
def gen_captcha_img(strText):
 width = 280
 height = 100
 #Create the image
 im = Image.new("RGB", (width, height), "black")

 fontFile = "/usr/share/fonts/dejavu/DejaVuSans.ttf"
 rand = random.randint
 #Set the font and its size
 font = ImageFont.truetype(fontFile, 50)

 #Get image size
 x, y = im.size

 #Create an object that can be used to draw in the given image
 draw = ImageDraw.Draw(im)

 #Draw the text
 #fontColor = (rand(0,255), rand(0,255), rand(0,255))
 fontColor = "#fff"
 draw.text((35,25), strText, font=font, fill=fontColor)

 for i in range(15):
  draw.line((rand(0,x),rand(0,y), rand(0,x),rand(0,y)), fill=(rand(0,255), rand(0,255), rand(0,255)))

#   pxColor = "#fff"
 pxColor = (rand(0,255), rand(0,255), rand(0,255))
#   color += str(hex(rand(0,4095)))[2:5]
 #Draw points (individual pixels) inside the image area
 for i in range(300):
  draw.point((rand(0,x),rand(0,y),rand(0,x),rand(0,y)), fill=pxColor)

 #Apply a filter to the image
 im = im.filter(ImageFilter.BLUR)
 im = im.filter(ImageFilter.EDGE_ENHANCE_MORE)

 im.rotate(rand(0,90)-45).save(strText + ext)
#   im.save(strText + ext)


def gen_random_captcha(makeCnt):
 gen_tx = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()"
 textRand = random.randint
 textLen = 6
 for i in range(makeCnt):
  text = ""
  for j in range(textLen):
   text += gen_tx[textRand(0, len(gen_tx)-1)]

  gen_captcha_img(text)

gen_random_captcha(makeCnt)
print "made a captcha\n"

'리눅스 서버에 대해서 > python' 카테고리의 다른 글

파이선 간단한 captchr 소스  (0) 2013.09.20
파이선 PIL 간단 예제  (0) 2013.09.20
파이썬의 PIL 이미지 라이브러리 사용 강좌  (0) 2013.09.18
captcha 우회하기  (0) 2013.09.18
CAPTCHA 만들기  (0) 2013.05.15

+ Recent posts