Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/site-packages/PIL/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/site-packages/PIL/__pycache__/ImageDraw.cpython-35.pyc



�ʴW�3�@s�ddlZddlZddlmZmZddlmZGdd�de�Zddd�Z	yej
jZWne
k
r�dZYnXdddd	�Zdd
d�ZdS)�N)�Image�
ImageColor)�isStringTypec@sreZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zddd
�Zddd�Z	ddd�Z
dddd�Zdddd�Zdddd�Z
dddd�Zdddd�Zddd�Zdddd �Zddd!d"�Zd#d$�Zd%d&�Zdddd'd(�Zdddd)d*d+d,�Zdd-d.�Zdd)d/d0�ZdS)1�	ImageDrawNcCsA|j�|jr|j�d}|dkr8|j}||jkrw|dkrk|jdkrkd}ntd��|dkr�|j|_n	d|_|j|_tjj	|j|�|_	||_|dkr�|j	j
d|�|_n|j	j
d
|�|_|dkr"d
|_n	d|_d|_
d|_dS)a�
        Create a drawing instance.

        @param im The image to draw in.
        @param mode Optional mode to use for color values.  For RGB
           images, this argument can be RGB or RGBA (to blend the
           drawing into the image).  For all other modes, this argument
           must be the same as the image mode.  If omitted, the mode
           defaults to the mode of the image.
        rNZRGBAZRGB�z
mode mismatch�P�I�F�1�L)rr	���)r
rrr	)�load�readonlyZ_copy�mode�
ValueError�palette�imr�core�draw�draw_ink�ink�fontmode�fill�font)�selfrrZblend�r�@/opt/alt/python35/lib64/python3.5/site-packages/PIL/ImageDraw.py�__init__1s0
	
						zImageDraw.__init__cCstdd��dS)Nzsetink() has been removed. z%Please use keyword arguments instead.)�NotImplementedError)rrrrr�setinkZszImageDraw.setinkcCstdd��dS)Nzsetfill() has been removed. z%Please use keyword arguments instead.)r)rZonoffrrr�setfill^szImageDraw.setfillcCstjdd�||_dS)Nzsetfont() is deprecated. z*Please set the attribute directly instead.)�warnings�warnr)rrrrr�setfontbs	zImageDraw.setfontcCs/|js(ddlm}|j�|_|jS)zGet the current default font.r)�	ImageFont)r�PILr$Zload_default)rr$rrr�getfonths	zImageDraw.getfontcCs)|dkr9|dkr9|jr-|j}q|j}n�|dk	r�t|�rftj||j�}|jr�t|tj	�r�|jj|�}|j
j||j�}|dk	rt|�r�tj||j�}|jrt|tj	�r|jj|�}|j
j||j�}||fS)N)rrrrZgetcolorrr�
isinstance�numbers�Numberrr)rrrrrr�_getinkps"	zImageDraw._getinkcCs>|j|�\}}|dk	r:|jj||||�dS)zDraw an arc.N)r*rZdraw_arc)r�xy�start�endrrrrr�arc�sz
ImageDraw.arccCsZ|j�|j|�\}}|dkr1|}|dk	rV|jj||j|�dS)zDraw a bitmap.N)r
r*r�draw_bitmapr)rr+�bitmaprrrrrr0�s
zImageDraw.bitmapcCsl|j||�\}}|dk	r@|jj||||d�|dk	rh|jj||||d�dS)z
Draw a chord.Nrr)r*rZ
draw_chord)rr+r,r-r�outlinerrrr�chord�s
zImageDraw.chordcCs`|j||�\}}|dk	r:|jj||d�|dk	r\|jj||d�dS)zDraw an ellipse.Nrr)r*rZdraw_ellipse)rr+rr1rrrr�ellipse�s
zImageDraw.ellipsercCs;|j|�\}}|dk	r7|jj|||�dS)z6Draw a line, or a connected sequence of line segments.N)r*rZ
draw_lines)rr+r�widthrrrr�line�szImageDraw.linecCsj|j�|j||�\}}|dk	rD|jj||d�|dk	rf|jj||d�dS)z(Experimental) Draw a shape.Nrr)�closer*rZdraw_outline)r�shaperr1rrrrr7�s
zImageDraw.shapecCsl|j||�\}}|dk	r@|jj||||d�|dk	rh|jj||||d�dS)zDraw a pieslice.Nrr)r*rZ
draw_pieslice)rr+r,r-rr1rrrr�pieslice�s
zImageDraw.pieslicecCs8|j|�\}}|dk	r4|jj||�dS)z#Draw one or more individual pixels.N)r*rZdraw_points)rr+rrrrr�point�szImageDraw.pointcCs`|j||�\}}|dk	r:|jj||d�|dk	r\|jj||d�dS)zDraw a polygon.Nrr)r*rZdraw_polygon)rr+rr1rrrr�polygon�s
zImageDraw.polygoncCs`|j||�\}}|dk	r:|jj||d�|dk	r\|jj||d�dS)zDraw a rectangle.Nrr)r*rZdraw_rectangle)rr+rr1rrrr�	rectangle�s
zImageDraw.rectanglecCs+t|td��rdnd}||kS)z
Draw text.��
s
)r'�type)r�text�split_characterrrr�_multiline_check�s!zImageDraw._multiline_checkcCs.t|td��rdnd}|j|�S)Nr<r=s
)r'r>�split)rr?r@rrr�_multiline_split�s!zImageDraw._multiline_splitcOs(|j|�r.|j|||||||�S|j|�\}}|dkr[|j�}|dkrm|}|dk	r$yC|j||j�\}	}
|d|
d|d|
df}WnOtk
r
y|j||j�}	Wn!tk
r|j|�}	YnXYnX|j	j
||	|�dS)Nrr)rA�multiline_textr*r&Zgetmask2r�AttributeErrorZgetmask�	TypeErrorrr/)rr+r?rr�anchor�args�kwargsr�mask�offsetrrrr?�s$
(

zImageDraw.text��leftcCsDg}d}	|j|�}
|jdd|�d|}xB|
D]:}|j||�\}
}|j|
�t|	|
�}	q?W|\}}x�t|
�D]�\}}|dkr�nX|dkr�||	||d7}n3|dkr�||	||7}nd	s	td
��|j||f||||�||7}|d}q�WdS)Nr�ArrrM�centerg@�rightFz)align must be "left", "center" or "right")rC�textsize�append�max�	enumerate�AssertionErrorr?)rr+r?rrrG�spacingZalignZwidths�	max_width�lines�line_spacingr5�
line_width�line_heightrM�top�idxrrrrD�s(


zImageDraw.multiline_textcOsJ|j|�r%|j||||�S|dkr=|j�}|j|�S)z*Get the size of a given string, in pixels.N)rA�multiline_textsizer&�getsize)rr?rrHrIrrrrQ
s
zImageDraw.textsizec
Cs~d}|j|�}|jdd|�d|}x5|D]-}|j||�\}}	t||�}q9W|t|�|fS)NrrNrr)rCrQrS�len)
rr?rrVrWrXrYr5rZr[rrrr^s
zImageDraw.multiline_textsize)�__name__�
__module__�__qualname__rrr r#r&r*r.r0r2r3r5r7r8r9r:r;rArCr?rDrQr^rrrrr/s.)				rcCs7y|j|�SWntk
r2t||�SYnXdS)a�
    A simple 2D drawing interface for PIL images.

    @param im The image to draw in.
    @param mode Optional mode to use for color values.  For RGB
       images, this argument can be RGB or RGBA (to blend the
       drawing into the image).  For all other modes, this argument
       must be the same as the image mode.  If omitted, the mode
       defaults to the mode of the image.
    N)�getdrawrEr)rrrrr�Draws
recCs}d}|sd|krByddlm}Wntk
rAYnX|dkr^ddlm}|rs|j|�}||fS)z�
    (Experimental) A more advanced 2D drawing interface for PIL images,
    based on the WCK interface.

    @param im The image to draw in.
    @param hints An optional list of hints.
    @return A (drawing context, drawing resource factory) tuple.
    NZnicestr)�_imagingagg)�
ImageDraw2)r%rf�ImportErrorrgre)rZhints�handlerrrrrd4s
rdc
Cs9|j�}|\}}y4|||f}||kr;dS||||f<Wntk
rddSYnX||fg}|dkrVx�|rRg}	x�|D]�\}}x�|d|f|d|f||df||dffD]d\}
}y||
|f}Wntk
rYq�X||kr�|||
|f<|	j|
|f�q�Wq�W|	}q�Wn�x�|r4g}	x�|D]�\}}x�|d|f|d|f||df||dffD]p\}
}y||
|f}Wntk
r�Yq�X||kr�||kr�|||
|f<|	j|
|f�q�WqlW|	}qYWdS)a�
    (experimental) Fills a bounded region with a given color.

    @param image Target image.
    @param xy Seed position (a 2-item coordinate tuple).
    @param value Fill color.
    @param border Optional border value.  If given, the region consists of
        pixels with a color different from the border color.  If not given,
        the region consists of pixels having the same color as the seed
        pixel.
    Nr)r
�
IndexErrorrR)
Zimager+�valueZborderZpixel�x�yZ
backgroundZedgeZnewedge�s�t�prrr�	floodfillLsF

		G

	G
rq)r(r!r%rrZ	PIL._utilr�objectrrerr1ZOutlinerErdrqrrrr�<module>!s
�