http://www.emoticode.net/python/create-an-image-using-pil-python-imaging-library.html
#!/usr/bin/python import Image import ImageDraw import ImageFont import ImageFilter import cStringIO import random def gen_captcha_img(txt): #Create the image im = Image.new("RGB", (140,40), "#444") #Create an object that can be used to draw in the given image draw = ImageDraw.Draw(im) #Get image size x, y = im.size pnt = random.randint #Draw points (individual pixels) inside the image area for i in range(300): draw.point((pnt(0,x),pnt(0,y),pnt(0,x),pnt(0,y)), fill="#666") #Set the font and its size font = ImageFont.truetype("../font/Cashier.ttf", 30) #Draw the text draw.text((5,3), txt, font=font, fill="#fff") #Apply a filter to the image im = im.filter(ImageFilter.EDGE_ENHANCE_MORE) #Create a string buffer f = cStringIO.StringIO() #Save the image in the sting buffer (instead of in a file) im.save(f, "JPEG") #Get the string buffer content content = f.getvalue() f.close() #Base64 encode for data URI scheme data_uri = content.encode("base64").replace("\n", "") #Show the image according to data URI scheme img = '<img src="https://t1.daumcdn.net/cfile/tistory/2445A23756E6610337" />' % (data_uri) print img print "Content-type: text/html\n" gen_captcha_img("emoticode")
이걸 응용하면 좋을듯
'리눅스 서버에 대해서 > python' 카테고리의 다른 글
파이선으로 만든 간단한 captcha (0) | 2013.09.20 |
---|---|
파이선 PIL 간단 예제 (0) | 2013.09.20 |
파이썬의 PIL 이미지 라이브러리 사용 강좌 (0) | 2013.09.18 |
captcha 우회하기 (0) | 2013.09.18 |
CAPTCHA 만들기 (0) | 2013.05.15 |