Your IP : 216.73.216.85


Current Path : /opt/alt/python35/lib/python3.5/site-packages/captcha/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/captcha/__pycache__/image.cpython-35.pyc



e�V��@s~dZddlZddlZddlmZddlmZddlmZddlm	Z	yddl
mZWn"e
k
r�ddlmZYnXydd	lmZWne
k
r�dZYnXejjejjejje��d
�Zejjed�gZer dd
gZn	dgZGdd�de�ZGdd
�d
e�ZGdd�de�Zddd�ZdS)zq
    captcha.image
    ~~~~~~~~~~~~~

    Generate Image CAPTCHAs, just the normal image CAPTCHAs you are using.
�N)�Image)�ImageFilter)�Draw)�truetype)�StringIO)�BytesIO)�image�datazDroidSansMono.ttf�ImageCaptcha�
WheezyCaptchac@s.eZdZddd�Zddd�ZdS)�_CaptchaZpngcCs<|j|�}t�}|j|d|�|jd�|S)z�Generate an Image Captcha of the given characters.

        :param chars: text to be generated.
        :param format: image file format
        �formatr)�generate_imager�save�seek)�self�charsr
�im�out�r�>/opt/alt/python35/lib/python3.5/site-packages/captcha/image.py�generate"s
	
z_Captcha.generatecCs"|j|�}|j|d|�S)z�Generate and write an image CAPTCHA data to the output.

        :param chars: text to be generated.
        :param output: output destionation.
        :param format: image file format
        r
)rr)rr�outputr
rrrr�write.sz_Captcha.writeN)�__name__�
__module__�__qualname__rrrrrrr!src@s7eZdZdZddddd�Zdd�ZdS)	rz,Create an image CAPTCHA with wheezy.captcha.���KNcCs%||_||_|pt|_dS)N)�_width�_height�
DEFAULT_FONTS�_fonts)r�width�height�fontsrrr�__init__;s		zWheezyCaptcha.__init__cCs�tj�tj�tj�g}tjdtj�tjd|jd|�tj�tj	�tj
�gd|jd|j�}||�S)NZdrawingsr%r#r$)
�wheezy_captchaZwarp�rotate�offset�captcha�
background�textr"ZcurveZnoiseZsmoothrr )rrZ
text_drawings�fnrrrr@s							zWheezyCaptcha.generate_image)rrr�__doc__r&rrrrrr9sc@s�eZdZdZdddddd�Zedd��Zed	d
��Zeddd
d��Z	dd�Z
dd�ZdS)r
a�Create an image CAPTCHA.

    Many of the codes are borrowed from wheezy.captcha, with a modification
    for memory and developer friendly.

    ImageCaptcha has one built-in font, DroidSansMono, which is licensed under
    Apache License 2. You should always use your own fonts::

        captcha = ImageCaptcha(fonts=['/path/to/A.ttf', '/path/to/B.ttf'])

    You can put as many fonts as you like. But be aware of your memory, all of
    the fonts are loaded into your memory, so keep them a lot, but not too
    many.

    :param width: The width of the CAPTCHA image.
    :param height: The height of the CAPTCHA image.
    :param fonts: Fonts to be used to generate CAPTCHA images.
    :param font_sizes: Random choose a font size from this parameters.
    ��<NcCs=||_||_|pt|_|p*d|_g|_dS)N�.�:�D)r1r2r3)rr r!r"�_font_sizes�
_truefonts)rr#r$r%Z
font_sizesrrrr&hs
		zImageCaptcha.__init__cs<�jr�jSt�fdd��jD���_�jS)Ncs/g|]%}�jD]}t||��qqSr)r4r)�.0�n�s)rrr�
<listcomp>ts	z*ImageCaptcha.truefonts.<locals>.<listcomp>)r5�tupler")rr)rr�	truefontsos	zImageCaptcha.truefontscCs�|j\}}tjdt|d��}tj|t|d�|�}tj|d|t|d��}tj||t|d��}||f||fg}tjdd�}	tjdd�}
t|�j||
|	d|�|S)Nr�r/r��fill)�size�random�randint�intrZarc)r�color�w�h�x1�x2�y1�y2Zpoints�end�startrrr�create_noise_curvezs $ zImageCaptcha.create_noise_curve��c	Cs�t|�}|j\}}xk|r�tjd|�}tjd|�}|j||f|d|dffd|d|�|d8}qW|S)Nr�r>r#)rr?r@rA�line)	rrCr#�number�drawrDrErFrHrrr�create_noise_dots�s	3zImageCaptcha.create_noise_dotscsotjd�j�jf|�}t|�����fdd�}g}x!|D]}|j||��qRWtdd�|D��}t|�j�}	|j|	�jf�}t	|t
|��}
t	d|
�}t	|
d�}x�|D]x}
|
j\}}|
jd�j
d	d
��}|j|
|t	�j|d�f|�||tj|d�}q�W|S)
z�Create the CAPTCHA image itself.

        :param chars: text to be generated.
        :param color: color of the text.
        :param background: color of the background.

        The color should be a tuple of 3 numbers, such as (0, 255, 255).
        ZRGBcstj�j�}�j|d|�\}}tjdd�}tjdd�}tjd||||f�}t|�j||f|d|d��|j	|j
��}|jtjd
d�tj
dd	�}|tjd
d�}|tjdd�}ttj||��}ttj||��}ttj||��}	ttj||��}
|t|�t|	�}|t|�t|
�}|||||
||	||
||	|f}
|j||f�}|j||ftj|
�}|S)N�fontr��ZRGBAr>rN�expandrOg�������?g333333�?g�������?i��)r@�choicer;ZtextsizerAr�newrr,ZcropZgetbboxr(�uniformZBILINEARrB�abs�resizeZ	transformZQUAD)�crTrDrEZdxZdyrrFrHrGrIZw2Zh2r	)rCrRrrr�_draw_character�s. ('z:ImageCaptcha.create_captcha_image.<locals>._draw_charactercSsg|]}|jd�qS)r)r?)r6rrrrr9�s	z5ImageCaptcha.create_captcha_image.<locals>.<listcomp>g�?g�������?�LcSs|dS)Ng��Q���?r)�irrr�<lambda>�sz3ImageCaptcha.create_captcha_image.<locals>.<lambda>�r)rrYrr r�append�sum�maxr\rB�lenr?�convertZpointZpaster@rA)rrrCr+rr^Zimagesr]�
text_widthr#ZaverageZrandr)rrDrE�maskr)rCrRrr�create_captcha_image�s$	! 

*z!ImageCaptcha.create_captcha_imagecCsxtdd�}tddtjdd��}|j|||�}|j||�|j||�|jtj�}|S)zaGenerate the image of the given characters.

        :param chars: text to be generated.
        ���rr��)	�random_colorr@rArjrSrL�filterrZSMOOTH)rrr+rCrrrrr�szImageCaptcha.generate_image)rrrr.r&�propertyr;�staticmethodrLrSrjrrrrrr
Ts

AcCs_tj||�}tj||�}tj||�}|dkrO|||fS||||fS)N)r@rA)rKrJZopacityZredZgreenZbluerrrrn�s
rn)r.�osr@ZPILrrZ
PIL.ImageDrawrZ
PIL.ImageFontr�	cStringIOrr�ImportError�ioZwheezy.captcharr'�path�join�abspath�dirname�__file__ZDATA_DIRr!�__all__�objectrrr
rnrrrr�<module>s.

-	�