本文整理汇总了Python中captcha.image.ImageCaptcha.write方法的典型用法代码示例。如果您正苦于以下问题:Python ImageCaptcha.write方法的具体用法?Python ImageCaptcha.write怎么用?Python ImageCaptcha.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类captcha.image.ImageCaptcha
的用法示例。
在下文中一共展示了ImageCaptcha.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_image
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
def do_image():
# image = ImageCaptcha(fonts=['./comic.ttf', './comicbd.ttf'])
image = ImageCaptcha(width=100, height=50)
# data = image.generate('1234')
# assert isinstance(data, BytesIO)
image.write('1234', 'out.%s' % fmt_suffix.get(fmt, fmt), fmt=fmt)
示例2: do_image
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
def do_image():
# image = ImageCaptcha(fonts=['./comic.ttf', './comicbd.ttf'])
image = ImageCaptcha()
# data = image.generate('1234')
# assert isinstance(data, BytesIO)
image.write("1234", "out.jpeg", format="jpeg")
示例3: stress_image
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
def stress_image(i):
image = ImageCaptcha(width=100, height=50, fonts=['./Mirvoshar.ttf'], font_sizes=[50, 54, 57, 64])
d = str(i)
if os.path.exists(d):
shutil.rmtree(d)
os.makedirs(d)
for t in texts:
image.write(t, os.path.join(d, '%s.%s' % (t, fmt_suffix.get(fmt, fmt))), fmt=fmt)
示例4: gen_captcha
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
def gen_captcha(length=None):
length = length if length else LENGTH
image = ImageCaptcha(width=130, height=60) # fonts=FONTS)
text = random_text(length)
image.generate(text)
code_signature = sign(text)
fpath = os.path.join(OUTDIR, code_signature + ".png")
image.write(text, fpath)
return fpath, code_signature
示例5: gen_captcha_text_and_image
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
def gen_captcha_text_and_image():
image = ImageCaptcha()
#获得随机生成的验证码
captcha_text = random_captcha_text()
#把验证码列表转为字符串
captcha_text = ''.join(captcha_text)
#生成验证码
captcha = image.generate(captcha_text)
image.write(captcha_text, 'captcha/images/' + captcha_text + '.jpg') # 写到文件
示例6: gen_captcha_text_and_image
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
def gen_captcha_text_and_image():
image = ImageCaptcha()
captcha_text = random_captcha_text()
captcha_text = ''.join(captcha_text)
captcha = image.generate(captcha_text)
image.write(captcha_text, captcha_text + '.jpg') # 写到文件
captcha_image = Image.open(captcha)
captcha_image = np.array(captcha_image)
return captcha_text, captcha_image
示例7: generate_verification_code
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
def generate_verification_code(request):
'''
'''
code = random_code_generator(5)
image = ImageCaptcha()
image.write(code, 'captcha/{0}.png'.format(code))
verification_code = { 'verification_image': '{0}.png'.format(code),
'code': code}
return HttpResponse(json.dumps(verification_code),
status=200,
content_type='application/json')
示例8: myCaptchaLoader
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
def myCaptchaLoader(request):
to_json_response = dict()
image = None
try:
print "IN CAPTCHA METHOD....."
to_json_response['status'] = 1
image = ImageCaptcha(fonts=['Ubuntu-B.ttf', 'UbuntuMono-R.ttf'])
image.write('1234','out.png')
print "CAPTCHA CREATED..."
except:
print "\nException OCCURED",sys.exc_info()[0]
return StreamingHttpResponse(json.dumps(to_json_response),content_type="application/json")
示例9: appear
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
def appear(self):
# Make captcha
row = str(uuid.uuid4())[:4]
img = ImageCaptcha()
data = img.generate("1")
assert isinstance(data, BytesIO)
img.write(row, "captcha.png")
pixmap = QtGui.QPixmap("captcha.png")
self.ui.captcha_lb.setPixmap(pixmap)
os.remove("captcha.png")
# Appear win
self.show()
self.animation_appear.start()
示例10: newcaptcha
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
def newcaptcha(text, fontspath='captcha/fonts/'):
cherrypy.session['capt_code'] = text
fonts = []
for x in os.listdir(fontspath):
if x.split('.')[-1] == 'ttf':#if font file
fonts.append(fontspath+x)
img = StringIO.StringIO()
image = ImageCaptcha(fonts=fonts)
data = image.generate(text)
image.write(text, img)
contents = img.getvalue()
img.close()
return contents
示例11: id_generator
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
from captcha.image import ImageCaptcha
import string
import random
path = "images/"
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
image = ImageCaptcha(fonts=['OpenSans-Regular.ttf'], width=250)
for x in range(0, 10000):
randString = id_generator()
image.write(randString, path + randString + "-" + str(x) + ".png")
示例12: ImageCaptcha
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
from captcha.image import ImageCaptcha
import os
import random
hash = SHA256.new()
semilla=""
r=0
image = ImageCaptcha(fonts=['./fon/A.ttf', './fon/B.ttf'])
for i in range(5):
r=random.randrange(100)
semilla=semilla+chr(r)
print str(i)+" "+str(r)+" "+chr(r)+" "+semilla
print semilla+"\n"
data = image.generate(semilla)
image.write(semilla, '/tmp/out.png')
image.write(semilla, 'out.png')
os.remove("/tmp/out.png")
hash.update(semilla)
otra=hash.digest()
llave = ""
print otra
for i in range(16):
llave=llave+otra[i]
print str(i)+" "+otra[i]+" "+llave
print "\n"
print llave
archy=open('llave.txt','w')
示例13: ImageCaptcha
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
__author__ = 'wenjusun'
from io import BytesIO
from captcha.image import ImageCaptcha
import random
image = ImageCaptcha(fonts=['/var/shijing/Abyssinica_SIL.ttf', '/usr/share/fonts/vlgothic/VL-Gothic-Regular.ttf'])
data = image.generate('1234')
#assert isinstance(data, BytesIO)
image.write('1234', 'out.png')
class CaptchImage():
def get_path(self):
return ""
def generate_captch(self):
return ""
ch_az=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'0','1','2','3','4','5','6','7','8','9']
def get_random_characters(width=4):
return random.sample(ch_az,width)
示例14: ImageCaptcha
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
from io import BytesIO
from captcha.image import ImageCaptcha
import base64
image = ImageCaptcha()
captcha_text = "humble"
data = image.generate(captcha_text)
assert isinstance(data, BytesIO)
image.write(captcha_text, "out.png")
# print('data')
# print(type(data))
# print(type(data.getvalue()))
# print(str(data.getvalue()))
encoded = base64.b64encode(data.getvalue())
print(encoded)
# with open('out.png', 'r') as f:
# c = f.read()
# print(c)
示例15: ImageCaptcha
# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import write [as 别名]
from captcha.image import ImageCaptcha
image = ImageCaptcha(fonts=['C:\\Users\\user\\Desktop\\RandomCodes\\CaptchaGenerator\\A.ttf'])
data = image.generate('I am Pragyaditya Das')
image.write('I am Pragyaditya Das', 'out.png')