コード例 #1
0
ファイル: captcha.py プロジェクト: eomsoft/teleport
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()
コード例 #2
0
ファイル: captcha.py プロジェクト: windard/Flasky
 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()
     ])
コード例 #3
0
ファイル: utils.py プロジェクト: myisjon/mirrors_server
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'))
コード例 #4
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.')
コード例 #5
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()
コード例 #6
0
def generate_image(num):
    captcha_model = captcha(
        width=IMAGE_WIDTH,
        height=IMAGE_HEIGHT,
        drawings=[
            background(color='#FFFFFF'),
            text(font_sizes=[19, 20, 21, 22],
                 fonts=[FONT_PATH],
                 drawings=[rotate(angle=15),
                           offset(0.10, 0.10)],
                 start_x=0,
                 start_y=0,
                 squeeze_factor=0.88),
        ])

    label = random_chars(num)

    imgsrc = captcha_model(label)

    image = imgsrc.convert('L')
    imgpx = image.load()

    img_process.binary(image, imgpx, THRESHOLD + random.randint(-20, 15))
    img_process.clear_noise(image, imgpx)

    # image_array = np.array(image)
    # plt.imshow(image_array)
    fp = BytesIO()
    image.save(fp, 'JPEG')
    return fp.getvalue(), label
コード例 #7
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)
コード例 #8
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)
コード例 #9
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)
コード例 #10
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)
コード例 #11
0
ファイル: view.py プロジェクト: zyhndesign/cidic-artifacts
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
コード例 #12
0
ファイル: view.py プロジェクト: shonenada/flask-captcha
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
コード例 #13
0
ファイル: image.py プロジェクト: aiguy110/captcha
 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)
コード例 #14
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
コード例 #15
0
ファイル: captcha.py プロジェクト: 404soul/Minos
	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)
コード例 #16
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
コード例 #17
0
ファイル: captchagenerator.py プロジェクト: Lukjam/projekt
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
コード例 #18
0
def code2image(code):
    size = current_app.config.get('VERIFY_CODE_FONT_SIZE', 36)
    drawer = image.captcha(
        drawings=[
            image.background(random.choice(BG_COLORS)),
            image.text(
                fonts=FONTS,
                font_sizes=(size, size + 2, size + 2),
                color=random.choice(TEXT_COLORS),
                drawings=[image.rotate(), image.offset()],
            ),
        ],
        width=size * len(code),
        height=size + 4,
    )
    buf = StringIO()
    pic = drawer(code)
    pic.save(buf, 'GIF')
    response = make_response(buf.getvalue())
    response.headers['Content-Type'] = 'image/gif'
    return response
コード例 #19
0
ファイル: tools.py プロジェクト: huxiaoqiang/chuangplus
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
コード例 #20
0
ファイル: verify.py プロジェクト: OdayWu/chiki
def code2image(code):
    size = current_app.config.get('VERIFY_CODE_FONT_SIZE', 36)
    drawer = image.captcha(
        drawings=[
            image.background(random.choice(BG_COLORS)),
            image.text(
                fonts=FONTS, 
                font_sizes=(size, size + 2, size + 2),
                color=random.choice(TEXT_COLORS), 
                drawings=[image.rotate(), image.offset()],
            ),
        ],
        width=size * len(code),
        height=size + 4,
    )
    buf = StringIO()
    pic = drawer(code)
    pic.save(buf, 'GIF')
    response = make_response(buf.getvalue())
    response.headers['Content-Type'] = 'image/gif'
    return response
コード例 #21
0
ファイル: captcha.py プロジェクト: zeplios/castle
 def GET(self, params):
     captcha_image = captcha(drawings=[
         background(),
         text(fonts=[
             path.join(_fontsDir,'DejaVuSans.ttf'),
             path.join(_fontsDir,'DejaVuSans-Bold.ttf')],
             drawings=[
                 #warp(),
                 #rotate(),
                 offset()
             ]),
         #curve(),
         #noise(),
         smooth()
     ])
     chars = random.sample(_chars, 4)
     session.captcha = ''.join(chars)
     image = captcha_image(chars)
     out = StringIO()
     image.save(out,"jpeg",quality=75)
     web.header('Content-Type','image/jpeg')
     return out.getvalue()
コード例 #22
0
ファイル: img.py プロジェクト: reorx/pi_router
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()
コード例 #23
0
ファイル: comments.py プロジェクト: ghtyrant/python-comments
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 })
コード例 #24
0
ファイル: generator.py プロジェクト: Charlemagne-3/DisCapTy
 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)
コード例 #25
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()
コード例 #26
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()
コード例 #27
0
import math
import captcha
import matplotlib.pyplot as plt

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

captcha_image = captcha(drawings=[
    background(color='whitesmoke'),
    text(fonts=['/Users/cortega/Documents/arcanine/comic-sans-ms.ttf'],
         drawings=[warp(), rotate(), offset()]),
    noise(),
    smooth()
])

image = captcha_image(random.sample(string.ascii_uppercase + string.digits, 4))
plt.imsave('test.png', image)
コード例 #28
0
ファイル: sample.py プロジェクト: hakanaku1234/wheezy-captcha
"""
"""

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)
コード例 #29
0
ファイル: captcha.py プロジェクト: eomsoft/teleport
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()
コード例 #30
0
ファイル: shared.py プロジェクト: alanljj/auth_captcha
            else:
                _logger.debug(u"redis:key="+key+u",时间超时,清除")
                self.r.delete(key)
        return None

    def delete(self, key, seconds=0, namespace=None):
        _logger.debug(u"redis:key="+key+u"被清除")
        return self.r.delete(key)

if config['workers']:
    import redis
    from time import time as unixtime
    cache = WrapperRedis()
else:
    from memory import MemoryCache
    cache = MemoryCache()

adp = os.path.abspath(config['addons_path'])
CourierNew = os.path.join(adp, 'auth_captcha', 'controllers', 'fonts',  'CourierNew-Bold.ttf')
LiberationMono = os.path.join(adp, 'auth_captcha', 'controllers', 'fonts', 'LiberationMono-Bold.ttf')

captcha_image = captcha(drawings=[
    background(),
    text(fonts=[CourierNew, LiberationMono], drawings=[warp(), rotate(), offset()]),
    curve(),
    noise(),
    smooth()
])


コード例 #31
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()
コード例 #32
0
ファイル: securityCode1.py プロジェクト: yaksea/lunchOrder
#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)
コード例 #33
0
from wheezy.captcha.image import warp, rotate, offset, background, text, curve, noise, smooth, captcha
from skimage.io import imshow
from sklearn.model_selection import train_test_split

# Captcha Generator Settings
fonts = ['./comic-sans-ms.ttf']
text_drawings = [
    #warp(dx_factor=0.27, dy_factor=0.21),
    rotate(angle=25),
    offset(dx_factor=0.1, dy_factor=0.2),
]
drawings = [
    background(color='#dcdcdc'),
    text(fonts=fonts,
         font_sizes=(28, 28, 28),
         drawings=text_drawings,
         color='#32fa32',
         squeeze_factor=1),
    #curve(),
    noise(number=60, color='#69d748', level=2),
    smooth(),
]

generator = captcha(drawings=drawings, width=150, height=50)


def captcha_gen(string_size, generator):
    string = chars_generator(string_size)
    img = generator(string)
    pix = np.array(img)
    return pix, string
コード例 #34
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()
コード例 #35
0
ファイル: shared.py プロジェクト: caosena5101/auth_captcha
                self.r.delete(key)
        return None

    def delete(self, key, seconds=0, namespace=None):
        _logger.debug(u"redis:key=" + key + u"被清除")
        return self.r.delete(key)


if config['workers']:
    import redis
    from time import time as unixtime
    cache = WrapperRedis()
else:
    from memory import MemoryCache
    cache = MemoryCache()

adp = os.path.abspath(config['addons_path'])
CourierNew = os.path.join(adp, 'auth_captcha', 'controllers', 'fonts',
                          'CourierNew-Bold.ttf')
LiberationMono = os.path.join(adp, 'auth_captcha', 'controllers', 'fonts',
                              'LiberationMono-Bold.ttf')

captcha_image = captcha(drawings=[
    background(),
    text(fonts=[CourierNew, LiberationMono],
         drawings=[warp(), rotate(), offset()]),
    curve(),
    noise(),
    smooth()
])