Exemplo n.º 1
0
def gen_captcha():
    captcha_image_t = captcha(
        width=136,
        height=36,
        drawings=[
            background(color='#eeeeee'),
            # curve(color='#4388d5', width=1, number=10),
            curve(color='#4388d5', width=1, number=10),
            curve(color='#af6fff', width=3, number=16),
            noise(number=80, color='#eeeeee', level=3),
            text(
                fonts=[os.path.join(cfg.res_path, 'fonts', '001.ttf')],
                # font_sizes=(28, 34, 36, 32),
                font_sizes=(34, 40, 32, 36),
                color='#63a8f5',
                # squeeze_factor=1.2,
                squeeze_factor=0.9,
                drawings=[
                    # warp(dx_factor=0.05, dy_factor=0.05),
                    warp(dx_factor=0.03, dy_factor=0.03),
                    rotate(angle=20),
                    offset()
                ]),
            # curve(color='#af6fff', width=3, number=16),
            noise(number=30, color='#eeeeee', level=2),
            smooth(),
        ])

    chars_t = random.sample(_captcha_chars, 4)
    image = captcha_image_t(chars_t)

    out = io.BytesIO()
    image.save(out, "jpeg", quality=100)
    # web.header('Content-Type','image/jpeg')
    return ''.join(chars_t), out.getvalue()
Exemplo n.º 2
0
def tp_captcha_generate_image(h):
    if h >= 32:
        captcha_image_t = captcha(
            width=136,
            height=36,
            drawings=[
                background(color='#eeeeee'),
                curve(color='#bbbbbb', width=6, number=12),
                curve(color=_random_color_line, width=2, number=30),
                curve(color='#cccccc', width=7, number=13),
                curve(color='#dddddd', width=8, number=14),
                text(fonts=[
                    os.path.join(tp_cfg().res_path, 'fonts', '001.ttf')
                ],
                    font_sizes=(h-5, h-2, h, h+2),
                    color=_random_color_font,
                    squeeze_factor=1.05,
                    drawings=[
                        warp(dx_factor=0.03, dy_factor=0.03),
                        rotate(angle=20),
                        offset()
                    ]),
                smooth(),
            ])
    else:
        captcha_image_t = captcha(
            width=int(h*3)+8,
            height=h,
            drawings=[
                background(color='#eeeeee'),
                noise(number=40, color='#dddddd', level=3),
                smooth(),
                text(fonts=[
                    os.path.join(tp_cfg().res_path, 'fonts', '001.ttf')
                ],
                    font_sizes=(h-3, h-2, h-1, h),
                    color=_random_color_font,
                    squeeze_factor=0.95,
                    drawings=[
                        warp(dx_factor=0.03, dy_factor=0.03),
                        rotate(angle=15),
                        offset()
                    ]),
                smooth(),
            ])

    chars_t = random.sample(_captcha_chars, 4)
    image = captcha_image_t(chars_t)

    out = io.BytesIO()
    image.save(out, "jpeg", quality=80)
    return ''.join(chars_t), out.getvalue()
Exemplo n.º 3
0
 def __init__(self,
              code,
              count=4,
              width=200,
              height=75,
              fonts_dir='static/fonts',
              captcha_type='png'):
     super(Captcha, self).__init__()
     self.code = code
     self.count = count
     self.width = width
     self.height = height
     self.fonts_dir = fonts_dir
     self.captcha_type = captcha_type
     self.captcha_image = captcha(drawings=[
         background(),
         text(fonts=[
             path.join(fonts_dir, '78640___.TTF'),
             path.join(fonts_dir, '46152___.TTF')
         ],
              drawings=[warp(), rotate(), offset()]),
         curve(),
         noise(),
         smooth()
     ])
Exemplo n.º 4
0
def create_check_image(timestamp):
    image_drawings = [
        background(),
        text(fonts=[
            os.path.join(settings.CHECK_IMAGE_FONTS_PATH, font_path)
            for font_path in os.listdir(settings.CHECK_IMAGE_FONTS_PATH)
        ],
             drawings=[warp(), rotate(), offset()]),
        curve(number=4),
        noise(),
        smooth(),
    ]
    image_layout = captcha(drawings=image_drawings)

    value = sample(settings.CHECK_STR, 4)
    image_file = 'tmp_check_{}.JPEG'.format(timestamp)
    image_layout(value).save(image_file)
    with open(image_file, 'rb') as f:
        image_base64 = b64encode(f.read())
        os.remove(image_file)
    image_id = '{}{}'.format(
        md5(sha1(image_base64).hexdigest().encode('utf-8')).hexdigest(),
        timestamp)
    image, is_image = CheckImage.objects.get_or_create(
        image_id=image_id, image_value=''.join(value))
    if is_image is False:
        return create_check_image(timestamp)
    return (image.image_id, image_base64.decode('utf-8'))
Exemplo n.º 5
0
def new_captcha():
    import random
    import string
    import StringIO
    value = ''
    img_date = ''
    try:
        captcha_image = captcha(drawings=[
            background('#fcf7e2'),
            text(fonts=[os.path.join( ttf_path,'ttf','OsakaMono.ttf')],
                font_sizes=(40,45,50),
                drawings=[
                    warp(),
                    rotate(),
                    offset()
                ],
                color='#4e97c7'
                ),
            curve('#4e97c7',width=0, number=2),
            noise(number=0),
            smooth()], 
            width=112, height=38)

        value = ''.join(random.sample(string.uppercase + string.digits, 4))
        image = captcha_image(value)
        img_file = StringIO.StringIO()
        image.save( img_file, 'jpeg', quality=80)
        img_file.seek(0)
        img_date = img_file.read()

    except Exception,ex:
        logging.error('create captcha img failed.')
Exemplo n.º 6
0
def init_captcha(pelican):
    if not 'PELICAPTCHA_FONT' in pelican.settings:
        raise Exception('please configure a font using the PELICAPTCHA_FONT config variable')
    fonts = [ pelican.settings['PELICAPTCHA_FONT'] ]
    text_drawings = [ warp(), rotate(), offset() ]
    text_function = text(fonts=fonts, drawings=text_drawings)
    drawings = [ background(), text_function, curve(), smooth() ]
    global captcha_image
    captcha_image = captcha(drawings)
Exemplo n.º 7
0
 def get(request):
     captcha_image = captcha(drawings=[
         background(),
         text(fonts=[path.join(Captcha._fontsDir, 'captcha.ttf')],
              drawings=[warp(), rotate(), offset()]),
         curve(),
         noise(),
         smooth()
     ])
     chars = random.sample(_chars, 4)
     image = captcha_image(chars)
     request.set_session(Captcha._session_name_, ''.join(chars))
     return image, ''.join(chars)
Exemplo n.º 8
0
    def generate_captcha(self):
        from wheezy.captcha.image import captcha
        from wheezy.captcha.image import background
        from wheezy.captcha.image import curve
        from wheezy.captcha.image import noise
        from wheezy.captcha.image import smooth
        from wheezy.captcha.image import text

        from wheezy.captcha.image import offset
        from wheezy.captcha.image import rotate
        from wheezy.captcha.image import warp

        import random
        import string

        def _file_to_base64(stream):

            image_data = base64.b64encode(stream)
            return 'data:image/{0};base64,{1}'.format('captcha_image', image_data)

        captcha_image = captcha(drawings=[
            text(
                fonts = [
                    '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf',
                    ],
                drawings=[
                    warp(0.5),
                    rotate(),
                    offset()
                ]),
            curve(),
            noise(),
            smooth()
        ], width=300)
        allowed_chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'
        captcha_string = ''
        for i in range(0, 5):
            captcha_string += random.choice(allowed_chars)
        #captcha_string = list(random.sample(string.uppercase + string.digits, 4))
        session['contact_form_captcha_key'] = ''.join(captcha_string)
        session.save()

        image = captcha_image(captcha_string)

        output = StringIO.StringIO()
        image.save(output, 'JPEG', quality=75)
        contents = output.getvalue()

        return _file_to_base64(contents)
Exemplo n.º 9
0
def captcha_view():
    out = StringIO()
    captcha_image = captcha(drawings=[
        background(),
        text(fonts=current_app.config['CAPTCHA_FONTS'],
             drawings=[warp(), rotate(), offset()]),
        curve(),
        noise(),
        smooth(),
    ])
    captcha_code = ''.join(sample_chars())
    imgfile = captcha_image(captcha_code)
    session['captcha'] = captcha_code
    imgfile.save(out, 'PNG')
    out.seek(0)
    response = make_response(out.read())
    response.content_type = 'image/png'
    return response
Exemplo n.º 10
0
def create_captcha():

    captcha_image = captcha(drawings=[
        background(),
        text(fonts=[
            os.path.join(os.path.abspath(os.path.dirname(__file__))) +
            '/fonts/Georgia.ttf',
            os.path.join(os.path.abspath(os.path.dirname(__file__))) +
            '/fonts/FreeSans.ttf'
        ],
             drawings=[warp(), rotate(), offset()]),
        curve(),
        noise(),
        smooth()
    ])

    chars = random.sample(string.ascii_letters + string.digits, 4)
    return captcha_image(chars), chars
 def generate_image(self, chars):
     text_drawings = [
         wheezy_captcha.warp(),
         wheezy_captcha.rotate(),
         wheezy_captcha.offset(),
     ]
     fn = wheezy_captcha.captcha(
         drawings=[
             wheezy_captcha.background(),
             wheezy_captcha.text(fonts=self._fonts, drawings=text_drawings),
             wheezy_captcha.curve(),
             wheezy_captcha.noise(),
             wheezy_captcha.smooth(),
         ],
         width=self._width,
         height=self._height,
     )
     return fn(chars)
Exemplo n.º 12
0
def captcha_view():
    out = StringIO()
    captcha_image = captcha(drawings=[
        background(),
        text(fonts=current_app.config['CAPTCHA_FONTS'],
             drawings=[warp(),rotate(), offset()]),
        curve(),
        noise(),
        smooth(),
    ], width=200, height=75)
    captcha_code = ''.join(sample_chars())
    imgfile = captcha_image(captcha_code)
    session['captcha'] = captcha_code.lower()
    imgfile.save(out, 'PNG')
    out.seek(0)
    response = make_response(out.read())
    response.content_type = 'image/png'
    return response
Exemplo n.º 13
0
 def generate_image(self, chars):
     text_drawings = [
         wheezy_captcha.warp(),
         wheezy_captcha.rotate(),
         wheezy_captcha.offset(),
     ]
     fn = wheezy_captcha.captcha(
         drawings=[
             wheezy_captcha.background(),
             wheezy_captcha.text(fonts=self._fonts, drawings=text_drawings),
             wheezy_captcha.curve(),
             wheezy_captcha.noise(),
             wheezy_captcha.smooth(),
         ],
         width=self._width,
         height=self._height,
     )
     return fn(chars)
Exemplo n.º 14
0
	def get(request):
		captcha_image = captcha(drawings=[
			background(),
			text(fonts=[
				path.join(Captcha._fontsDir,'captcha.ttf')],
				drawings=[
					warp(),
					rotate(),
					offset()
				]),
			curve(),
			noise(),
			smooth()
		])
		chars = random.sample(_chars, 4)
		image = captcha_image(chars)
		request.session[Captcha._session_name_] = ''.join(chars)
		#print request.session[Captcha._session_name_]
		return image, ''.join(chars)
Exemplo n.º 15
0
def create_captcha_image(code_list):
    try:
        font_file = path.join(path.dirname(path.abspath(__file__)), 'fonts',
                              'FreeSans.ttf')
        captcha_image = captcha(drawings=[
            text(fonts=[font_file],
                 font_sizes=[65],
                 drawings=[rotate(),
                           offset(dx_factor=0.3, dy_factor=0.1)]),
            curve()
        ])
        image = captcha_image(code_list)
        out = StringIO()
        image.save(out, "jpeg", quality=75)
        out = out.getvalue()
    except ImportError:
        out = None
        print 'captcha:', ''.join(code_list)
    return out
Exemplo n.º 16
0
def code2image(code):
    """ 将验证码生成验证码图片 """

    captcha_image = image.captcha(drawings=[
        background(),
        text(fonts=FONTS,
             drawings=[image.warp(
             ), image.rotate(), image.offset()]),
        image.curve(),
        image.noise(),
        image.smooth()
    ])

    image = captcha_image(code)
    out = StringIO()
    image.save(out, "jpeg", quality=75)
    response = make_response(out.getvalue())
    response.headers['Content-Type'] = 'image/jpeg'
    return response
Exemplo n.º 17
0
def my_captcha(fg_col='#5C87B2', bg_col='#EEEECC'):
    cap = captcha(
        drawings=[
            background(color=bg_col),
            text(fonts=['fonts/CourierNewBold.ttf'],
                 # font_sizes=[60, 50, 45, 65],
                 font_sizes=[40, 35, 45],
                 color=fg_col,
                 drawings=[
                     warp(dx_factor=0.2, dy_factor=0.3),
                     rotate(angle=20),
                     offset(dx_factor=0.4, dy_factor=0.5),
                 ]),
            curve(color=fg_col, width=3, number=20),
            noise(number=250, color=bg_col, level=2),
            smooth()
        ],
        width=400, height=50,
    )
    return cap
Exemplo n.º 18
0
def getNewCaptcha():
    captcha_image = captcha(drawings=[
       background(),
       text(fonts=[
          os.path.join(os.path.dirname(os.path.dirname(__file__)), 'fonts/CourierNew-Bold.ttf'),
          os.path.join(os.path.dirname(os.path.dirname(__file__)), 'fonts/LiberationMono-Bold.ttf')],
        drawings=[
            warp(),
            rotate(),
            offset()
        ]),
        curve(),
        noise(),
        smooth()
    ])

    rand_string = random.sample(string.uppercase + string.digits, 4)
    print(rand_string)
    image = captcha_image(rand_string)

    return ''.join(rand_string), image
Exemplo n.º 19
0
def text_to_image(text):
    image_factory = image.captcha(drawings=[
        image.background(),
        image.text(
            fonts=[
                _resource_path('MSYHBD.TTF'),
                _resource_path('MSYHBD.TTF')
            ],
            drawings=[
                image.warp(),
                image.rotate(),
                image.offset()
            ]
        ),
        image.curve(),
        image.noise(),
        image.smooth()
    ])
    image_obj = image_factory(list(text))
    buf = StringIO.StringIO()
    image_obj.save(buf, 'jpeg', quality=80)
    return buf.getvalue()
Exemplo n.º 20
0
def create_captcha(db):
    import random
    import string

    dt_thresh = datetime.datetime.now() - datetime.timedelta(minutes=30)
    old_captchas = db.query(Captcha).filter(Captcha.date_created <= dt_thresh).all()

    for c in old_captchas:
        try:
            os.remove("captcha/captcha_%s.jpg" % (c.id))
        except OSError as e:
            print("Error deleting captcha image 'captcha_%s.jpg': %s" % (c.id, e))

    db.query(Captcha).filter(Captcha.date_created <= dt_thresh).delete()

    value = ''.join(random.sample(string.uppercase + string.digits, 5))
    id = hashlib.sha1(value +  datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")).hexdigest()[:8]
    c = Captcha(value=value, id=id)
    db.add(c)
    db.flush()

    img = captcha(drawings=[
                    background(color="#FFFFFF"),
                    text(fonts=[
                            "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf"
                         ],
                         font_sizes=[60],
                         squeeze_factor=1.0,
                         color="#50504f",
                         drawings=[
                            warp(),
                    ]),
                    curve(color='#40403f'),
                    ])

    finished_img = img(value)
    finished_img.save('captcha/captcha_%s.jpg' % (c.id), 'JPEG', quality=75)

    return json.dumps({ "id": c.id })
Exemplo n.º 21
0
 def generate(
     self,
     chars: str,
     *,
     width: int = 300,
     height: int = 125,
     background_color: str = "#EEEECC",
     text_color: str = "#5C87B2",
     text_squeeze_factor: float = 0.8,
     noise_number: int = 30,
     noise_color: str = "#EEEECC",
     noise_level: int = 2,
     **kwargs,
 ):
     fn: PIL.Image = wheezy_captcha.captcha(
         drawings=[
             wheezy_captcha.background(background_color),
             wheezy_captcha.text(
                 fonts=self.fonts,
                 font_sizes=self.fonts_sizes,
                 drawings=[
                     wheezy_captcha.warp(),
                     wheezy_captcha.rotate(),
                     wheezy_captcha.offset(),
                 ],
                 color=text_color,
                 squeeze_factor=text_squeeze_factor,
             ),
             wheezy_captcha.curve(),
             wheezy_captcha.noise(number=noise_number,
                                  color=noise_color,
                                  level=noise_level),
             wheezy_captcha.smooth(),
         ],
         width=width,
         height=height,
     )
     return fn(chars)
Exemplo n.º 22
0
 def GET(self):
     print(_fontsDir)
     captcha_image = captcha(drawings=[
         background(),
         text(fonts=[
             path.join(_fontsDir,'Candara.ttf')],
             drawings=[
                 warp(),
                 rotate(),
                 offset()
             ]),
         curve(),
         noise(),
         smooth()
     ])
     chars = random.sample(_chars, 4)
     web.config.session_parameters['capctha'] = ''.join(chars)
     #session[SESSION_KEY_CAPTCHA] = ''.join(chars)
     image = captcha_image(chars)
     out = StringIO()
     image.save(out,"jpeg",quality=75)
     web.header('Content-Type','image/jpeg')
     return out.getvalue()
Exemplo n.º 23
0
    def get(self):
        temp_uid = self.get_cookie('_t')
        if not temp_uid:
            print('NO COOKIE!!!')
            self.finish()
            return

        # num = ''.join(random.sample('acdefghkmnprstuvwxyABCDEFGHKMNPRSTUVWXY345678', 4))
        num = ''.join(random.sample('1234567890', 4))

        print('CAPTCHA: [%s:%s]' % (temp_uid, num))
        self.master.setex('captcha:' + temp_uid, 60, num)

        captcha_image = captcha(
            drawings=[
                # background(),
                text(
                    fonts=[
                        # 'fonts/Lobster_Two/LobsterTwo-BoldItalic.ttf',
                        'fonts/Special_Elite/SpecialElite.ttf'
                    ],
                    drawings=[warp(), rotate(), offset()]),
                curve(),
                noise(),
                smooth(),
            ],
            width=300)

        image = captcha_image(num)
        fp = BytesIO()
        image.save(fp, 'JPEG', quality=60)

        fp.seek(0)

        self.set_header("Content-type", "image/jpeg")
        self.write(fp.read())
        self.finish()
Exemplo n.º 24
0
def tp_captcha_generate_image_v1(h):
    if h >= 32:
        captcha_image_t = captcha(
            width=136,
            height=36,
            drawings=[
                background(color='#eeeeee'),
                # curve(color='#4388d5', width=1, number=10),
                curve(color='#4388d5', width=1, number=10),
                curve(color='#af6fff', width=3, number=16),
                noise(number=80, color='#eeeeee', level=3),
                smooth(),
                text(fonts=[
                    os.path.join(tp_cfg().res_path, 'fonts', '001.ttf')
                ],
                    # font_sizes=(28, 34, 36, 32),
                    font_sizes=(h-4, h-2, h, h+1),
                    color='#63a8f5',
                    # squeeze_factor=1.2,
                    squeeze_factor=0.9,
                    drawings=[
                        # warp(dx_factor=0.05, dy_factor=0.05),
                        warp(dx_factor=0.03, dy_factor=0.03),
                        rotate(angle=20),
                        offset()
                    ]),
                curve(color='#af6fff', width=3, number=16),
                noise(number=20, color='#eeeeee', level=2),
                smooth(),
            ])
    else:
        captcha_image_t = captcha(
            width=int(h*3)+8,
            height=h,
            drawings=[
                background(color='#eeeeee'),
                # curve(color='#4388d5', width=1, number=10),
                curve(color='#4388d5', width=1, number=10),
                curve(color='#af6fff', width=3, number=16),
                noise(number=40, color='#eeeeee', level=2),
                smooth(),
                text(fonts=[
                    os.path.join(tp_cfg().res_path, 'fonts', '001.ttf')
                ],
                    # font_sizes=(28, 34, 36, 32),
                    font_sizes=(h-2, h-1, h, h+1),
                    color='#63a8f5',
                    # squeeze_factor=1.2,
                    squeeze_factor=0.9,
                    drawings=[
                        # warp(dx_factor=0.05, dy_factor=0.05),
                        warp(dx_factor=0.03, dy_factor=0.03),
                        rotate(angle=20),
                        offset()
                    ]),
                curve(color='#4388d5', width=1, number=8),
                noise(number=10, color='#eeeeee', level=1),
                # smooth(),
            ])

    chars_t = random.sample(_captcha_chars, 4)
    image = captcha_image_t(chars_t)

    out = io.BytesIO()
    image.save(out, "jpeg", quality=100)
    return ''.join(chars_t), out.getvalue()
Exemplo n.º 25
0
#encoding=utf-8
from wheezy.captcha.image import captcha, background, text, warp, rotate, offset, curve, noise, smooth
from os import path
import random


_fontsDir='E:\selfwork\lunchOrder\src\lunchOrder\\test\\'
_letter_cases = "abcdefghjkmnpqrstuvwxy" # 小写字母,去除可能干扰的i,l,o,z
_upper_cases = _letter_cases.upper() # 大写字母
_numbers = ''.join(map(str, range(3, 10))) # 数字
init_chars = ''.join((_letter_cases, _upper_cases, _numbers))

captcha_image_t = captcha(drawings=[
    background(),
    text(fonts=[
#         path.join(_fontsDir,'ae_AlArabiya.ttf'),
        path.join(_fontsDir,'FreeSans.ttf')],
        drawings=[
            warp(),
            rotate(),
            offset()
        ]),
    curve(),
    noise(),
    smooth()
])
chars_t = random.sample(init_chars, 4)
print chars_t

image_t = captcha_image_t(chars_t)
image_t.save('test.jpeg','jpeg',quality=75)
Exemplo n.º 26
0
def tp_captcha_generate_image(h):
    if h >= 32:
        captcha_image_t = captcha(width=136,
                                  height=36,
                                  drawings=[
                                      background(color='#eeeeee'),
                                      curve(color='#bbbbbb',
                                            width=6,
                                            number=12),
                                      curve(color=_random_color_line,
                                            width=2,
                                            number=30),
                                      curve(color='#cccccc',
                                            width=7,
                                            number=13),
                                      curve(color='#dddddd',
                                            width=8,
                                            number=14),
                                      text(fonts=[
                                          os.path.join(tp_cfg().res_path,
                                                       'fonts', '001.ttf')
                                      ],
                                           font_sizes=(h - 5, h - 2, h, h + 2),
                                           color=_random_color_font,
                                           squeeze_factor=1.05,
                                           drawings=[
                                               warp(dx_factor=0.03,
                                                    dy_factor=0.03),
                                               rotate(angle=20),
                                               offset()
                                           ]),
                                      smooth(),
                                  ])
    else:
        captcha_image_t = captcha(width=int(h * 3) + 8,
                                  height=h,
                                  drawings=[
                                      background(color='#eeeeee'),
                                      noise(number=40,
                                            color='#dddddd',
                                            level=3),
                                      smooth(),
                                      text(fonts=[
                                          os.path.join(tp_cfg().res_path,
                                                       'fonts', '001.ttf')
                                      ],
                                           font_sizes=(h - 3, h - 2, h - 1, h),
                                           color=_random_color_font,
                                           squeeze_factor=0.95,
                                           drawings=[
                                               warp(dx_factor=0.03,
                                                    dy_factor=0.03),
                                               rotate(angle=15),
                                               offset()
                                           ]),
                                      smooth(),
                                  ])

    chars_t = random.sample(_captcha_chars, 4)
    image = captcha_image_t(chars_t)

    out = io.BytesIO()
    image.save(out, "jpeg", quality=80)
    return ''.join(chars_t), out.getvalue()
Exemplo n.º 27
0
def tp_captcha_generate_image_v1(h):
    if h >= 32:
        captcha_image_t = captcha(
            width=136,
            height=36,
            drawings=[
                background(color='#eeeeee'),
                # curve(color='#4388d5', width=1, number=10),
                curve(color='#4388d5', width=1, number=10),
                curve(color='#af6fff', width=3, number=16),
                noise(number=80, color='#eeeeee', level=3),
                smooth(),
                text(
                    fonts=[
                        os.path.join(tp_cfg().res_path, 'fonts', '001.ttf')
                    ],
                    # font_sizes=(28, 34, 36, 32),
                    font_sizes=(h - 4, h - 2, h, h + 1),
                    color='#63a8f5',
                    # squeeze_factor=1.2,
                    squeeze_factor=0.9,
                    drawings=[
                        # warp(dx_factor=0.05, dy_factor=0.05),
                        warp(dx_factor=0.03, dy_factor=0.03),
                        rotate(angle=20),
                        offset()
                    ]),
                curve(color='#af6fff', width=3, number=16),
                noise(number=20, color='#eeeeee', level=2),
                smooth(),
            ])
    else:
        captcha_image_t = captcha(
            width=int(h * 3) + 8,
            height=h,
            drawings=[
                background(color='#eeeeee'),
                # curve(color='#4388d5', width=1, number=10),
                curve(color='#4388d5', width=1, number=10),
                curve(color='#af6fff', width=3, number=16),
                noise(number=40, color='#eeeeee', level=2),
                smooth(),
                text(
                    fonts=[
                        os.path.join(tp_cfg().res_path, 'fonts', '001.ttf')
                    ],
                    # font_sizes=(28, 34, 36, 32),
                    font_sizes=(h - 2, h - 1, h, h + 1),
                    color='#63a8f5',
                    # squeeze_factor=1.2,
                    squeeze_factor=0.9,
                    drawings=[
                        # warp(dx_factor=0.05, dy_factor=0.05),
                        warp(dx_factor=0.03, dy_factor=0.03),
                        rotate(angle=20),
                        offset()
                    ]),
                curve(color='#4388d5', width=1, number=8),
                noise(number=10, color='#eeeeee', level=1),
                # smooth(),
            ])

    chars_t = random.sample(_captcha_chars, 4)
    image = captcha_image_t(chars_t)

    out = io.BytesIO()
    image.save(out, "jpeg", quality=100)
    return ''.join(chars_t), out.getvalue()
Exemplo n.º 28
0
"""
"""

from wheezy.captcha.image import captcha

from wheezy.captcha.image import background
from wheezy.captcha.image import curve
from wheezy.captcha.image import noise
from wheezy.captcha.image import smooth
from wheezy.captcha.image import text

from wheezy.captcha.image import offset
from wheezy.captcha.image import rotate
from wheezy.captcha.image import warp

if __name__ == '__main__':
    import random
    import string
    captcha_image = captcha(drawings=[
        background(),
        text(fonts=[
            'fonts/CourierNew-Bold.ttf', 'fonts/LiberationMono-Bold.ttf'
        ],
             drawings=[warp(), rotate(), offset()]),
        curve(),
        noise(),
        smooth()
    ])
    image = captcha_image(random.sample(string.uppercase + string.digits, 4))
    image.save('sample.jpg', 'JPEG', quality=75)