我创建了一个生成验证图像的python脚本。
import tornado.web, sys, json, io
class CaptchaHandler(tornado.web.RequestHandler):
def get(self):
from PIL import Image
from PIL import ImageDraw
from random import randint
from PIL import ImageFont
self.img = Image.new( 'RGB', (200,100), "black")
pixels = self.img.load()
for i in range(self.img.size[0]):
for j in range(self.img.size[1]):
pixels[i,j] = (i, j, 100)
draw = ImageDraw.Draw(self.img)
xy = ( randint(0, 180), randint(0, 80) )
txt = str(randint(1000, 9999))
font = ImageFont.truetype("arial.ttf", 28)
draw.text( xy, txt, (255,255,255), font )
del draw
o = io.BytesIO()
self.img.save(o, format="JPEG")
s = o.getvalue()
self.set_header('Content-type', "image/jpeg")
self.set_header('Content-length', len(s))
print(xy)
self.write(s)
class captcha_test(tornado.web.Application):
def __init__(self):
handlers = [(r"/captcha", CaptchaHandler),]
tornado.web.Application.__init__(self, handlers,)
def test_captacha():
application = captcha_test()
application.listen(8086)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
test_captacha()
我正在打印xy位置,它会打印出来