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")

 

 

이걸 응용하면 좋을듯

블로그 이미지

프로그래머 지향자 RosaGigantea

바쁜 일상 생활중의 기억 장소