当前位置: 首页>>代码示例>>Python>>正文


Python ImageCaptcha.generate方法代码示例

本文整理汇总了Python中captcha.image.ImageCaptcha.generate方法的典型用法代码示例。如果您正苦于以下问题:Python ImageCaptcha.generate方法的具体用法?Python ImageCaptcha.generate怎么用?Python ImageCaptcha.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在captcha.image.ImageCaptcha的用法示例。


在下文中一共展示了ImageCaptcha.generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_image_generate

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [as 别名]
    def test_image_generate():
        captcha = ImageCaptcha()
        data = captcha.generate('1234')
        assert hasattr(data, 'read')

        captcha = WheezyCaptcha()
        data = captcha.generate('1234')
        assert hasattr(data, 'read')
开发者ID:MaxMillion,项目名称:captcha,代码行数:10,代码来源:test_image.py

示例2: gen_captcha

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [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
开发者ID:lroolle,项目名称:CodingInPython,代码行数:11,代码来源:captcha.py

示例3: getCaptcha

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [as 别名]
 def getCaptcha(self):
     _chars = 'ABCDEFGHJKLMNPQRSTUVWXY23456789'
     chars = random.sample(_chars, 4)
     self.session.captcha = (''.join(chars)).lower()
     image = ImageCaptcha(fonts=['./static/fonts/arial.ttf', './static/fonts/arial.ttf'])
     data = image.generate(chars)
     return data
开发者ID:ThinCat,项目名称:PonyBlog,代码行数:9,代码来源:authcode.py

示例4: on_get

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [as 别名]
    def on_get(self, req, resp):
        # Generate a new captcha

        image = ImageCaptcha(fonts = ['fonts/UbuntuMono-R.ttf'])

        captcha_uuid = str(uuid.uuid4())
        captcha_answer = ''.join(random.SystemRandom().choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in range(6))
        captcha_image = 'data:image/png;base64,' + str(base64.b64encode(image.generate(captcha_answer).getvalue())).split("'")[1]

        # The answer should be case insensitive, the caps are just there for the bots
        captcha_answer = captcha_answer.lower()

        captcha = db.Captcha(
            uuid = captcha_uuid,
            answer_hash = nacl.hash.sha256(str.encode(captcha_uuid + captcha_answer), encoder = nacl.encoding.RawEncoder),
            ip_address_hash = nacl.hash.sha256(str.encode(captcha_uuid + req.remote_addr), encoder = nacl.encoding.RawEncoder),
            user_agent_hash = nacl.hash.sha256(str.encode(captcha_uuid + req.user_agent), encoder = nacl.encoding.RawEncoder)
        )

        db_session = req.context['db_session']

        db_session.add(captcha)
        db_session.commit()

        resp.status = falcon.HTTP_200
        resp.body = json.dumps({
            'uuid': captcha_uuid,
            'image': captcha_image
        })
开发者ID:jmaris,项目名称:keepsafe-server,代码行数:31,代码来源:keepsafe.py

示例5: gen_captcha_base64

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [as 别名]
def gen_captcha_base64(length=None):
    length = length if length else LENGTH
    image = ImageCaptcha(width=130, height=60)  # fonts=FONTS)
    text = random_text(length).lower()
    im = image.generate(text)
    code_signature = sign(text)
    b64 = base64.b64encode(im.getvalue()).decode("utf-8")
    return f"data:image/png;base64, {b64}", code_signature
开发者ID:lroolle,项目名称:CodingInPython,代码行数:10,代码来源:captcha.py

示例6: gen_captcha_text_and_image

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [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')  # 写到文件
开发者ID:zhangchungame,项目名称:helloTensorflow,代码行数:11,代码来源:10-1验证码生成.py

示例7: gen_captcha_image_random

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [as 别名]
def gen_captcha_image_random():
    image = ImageCaptcha()

    captcha_text = random_captcha_text()
    captcha_text = ''.join(captcha_text)

    captcha = image.generate(captcha_text)
    captcha_image = Image.open(captcha)
    captcha_image = np.array(captcha_image)
    print(captcha_image)
开发者ID:AlphaRgb,项目名称:flask,代码行数:12,代码来源:gen_captcha.py

示例8: gen_captcha_text_and_image

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [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
开发者ID:EstherLacan,项目名称:jiangfw,代码行数:14,代码来源:yanzhengma.py

示例9: gen_captcha_text_and_image

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [as 别名]
def gen_captcha_text_and_image():
	image = ImageCaptcha()

	# captcha_text = random_captcha_text()#使用带有字母和数字的随机组合
	captcha_text = random_captcha_num()#使用只有数字的随机组合
	captcha_text = ''.join(captcha_text)

	captcha = image.generate(captcha_text)
	# image.write(captcha_text, save_file+captcha_text + '.jpg')  # 写到文件

	captcha_image = Image.open(captcha)
	captcha_image = np.array(captcha_image)
	return captcha_text, captcha_image
开发者ID:zipingguo,项目名称:Hello-World,代码行数:15,代码来源:CreateAuthCode.py

示例10: main

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [as 别名]
    def main():
        parser = argparse.ArgumentParser()
        parser.add_argument("font_path", help="Path to ttf font file")
        parser.add_argument("output", help="Output filename including extension (e.g. 'sample.jpg')")
        parser.add_argument("--num", help="Up to 4 digit number [Default: random]")
        args = parser.parse_args()

        captcha = ImageCaptcha(fonts=[args.font_path])
        captcha_str = args.num if args.num else DigitCaptcha.get_rand(3, 4)
        img = captcha.generate(captcha_str)
        img = np.fromstring(img.getvalue(), dtype='uint8')
        img = cv2.imdecode(img, cv2.IMREAD_GRAYSCALE)
        cv2.imwrite(args.output, img)
        print("Captcha image with digits {} written to {}".format([int(c) for c in captcha_str], args.output))
开发者ID:CoderHHX,项目名称:incubator-mxnet,代码行数:16,代码来源:captcha_generator.py

示例11: request_img

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [as 别名]
def request_img(request):
    captcha_id = request.params['id']
    if not captcha_id:
        return HTTPNotFound('Not Found Resource')
    with transaction.manager:
        captcha = DBSession.query(CaptchaCode).get(captcha_id)
        if not captcha:
            return HTTPNotFound('Not Found Resource')

        image = ImageCaptcha(fonts=[ttf_path], font_sizes=(48, 49, 50), width=130)
        image_data = image.generate(captcha.code)
        response = Response(image_data.read())
        response.content_type = "image/jpeg"
        return response
开发者ID:vincentwyshan,项目名称:tap,代码行数:16,代码来源:tcaptcha.py

示例12: appear

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [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()
开发者ID:CLitchi,项目名称:Enloren,代码行数:16,代码来源:register.py

示例13: gen_captcha_text_and_image

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [as 别名]
def gen_captcha_text_and_image():
    while (1):
        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.show()
        captcha_image = np.array(captcha_image)
        if captcha_image.shape == (60, 160, 3):
            break

    return captcha_text, captcha_image
开发者ID:Kingson4Wu,项目名称:python2-demo,代码行数:19,代码来源:gen_captcha.py

示例14: OCRIter

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [as 别名]
class OCRIter(mx.io.DataIter):
    def __init__(self, count, batch_size, num_label, init_states):
        super(OCRIter, self).__init__()
        global SEQ_LENGTH
        # you can get this font from http://font.ubuntu.com/
        self.captcha = ImageCaptcha(fonts=['./data/Xerox.ttf'])
        self.batch_size = batch_size
        self.count = count
        self.num_label = num_label
        self.init_states = init_states
        self.init_state_arrays = [mx.nd.zeros(x[1]) for x in init_states]
        self.provide_data = [('data', (batch_size, 80, 30))] + init_states
        self.provide_label = [('label', (self.batch_size, 4))]
        self.cache_data = []
        self.cache_label = []

    def __iter__(self):
        print('iter')
        init_state_names = [x[0] for x in self.init_states]
        for k in range(self.count):
            data = []
            label = []
            for i in range(self.batch_size):
                num = gen_rand()
                img = self.captcha.generate(num)
                img = np.fromstring(img.getvalue(), dtype='uint8')
                img = cv2.imdecode(img, cv2.IMREAD_GRAYSCALE)
                img = cv2.resize(img, (80, 30))
                img = img.transpose(1, 0)
                img = img.reshape((80, 30))
                img = np.multiply(img, 1 / 255.0)
                data.append(img)
                label.append(get_label(num))

            data_all = [mx.nd.array(data)] + self.init_state_arrays
            label_all = [mx.nd.array(label)]
            data_names = ['data'] + init_state_names
            label_names = ['label']

            data_batch = SimpleBatch(data_names, data_all, label_names, label_all)
            yield data_batch

    def reset(self):
        self.cache_data.clear()
        self.cache_label.clear()
        pass
开发者ID:Piyush3dB,项目名称:mxnet,代码行数:48,代码来源:lstm_ocr.py

示例15: add_to_form_context

# 需要导入模块: from captcha.image import ImageCaptcha [as 别名]
# 或者: from captcha.image.ImageCaptcha import generate [as 别名]
def add_to_form_context(context):
    config = pluginapi.get_config('mediagoblin.plugins.lepturecaptcha')
    captcha_secret = config.get('CAPTCHA_SECRET_PHRASE')
    captcha_charset = config.get('CAPTCHA_CHARACTER_SET')
    captcha_length = config.get('CAPTCHA_LENGTH')

    captcha_string = u''.join([choice(captcha_charset) for n in xrange(captcha_length)])

    captcha_hash = sha1(captcha_secret + captcha_string).hexdigest()
    context['captcha_hash'] = captcha_hash

    image = ImageCaptcha()
    data = image.generate(captcha_string)
    captcha_image = base64.b64encode(data.getvalue())
    context['captcha_image'] = captcha_image

    return context
开发者ID:ayleph,项目名称:mediagoblin-lepture_captcha,代码行数:19,代码来源:__init__.py


注:本文中的captcha.image.ImageCaptcha.generate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。