Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
3 ia @sddlZddlZddlmZmZmZGdddZdddZy ejj Z Wne k r`dZ YnXddd Z dd d Z d d ZddZdS)N)Image ImageColor ImageFontc @seZdZd7ddZddZd8ddZd9d d Zd:d d Zd;d dZdddZ d?ddZ d@ddZ dAddZdBddZdCddZdDd d!Zd"d#Zd$d%ZdEd)d*ZdFd+d,ZdGd-d.ZdHd/d0ZdId1d2ZdJd3d4ZdKd5d6ZdS)L ImageDrawNcCs|j|jr|jd}|dkr(|j}||jkrR|dkrJ|jdkrJd}ntd|dkrd|j|_nd|_||_|j|_tj j |j||_ ||_|d kr|j j d|_ n|j j d |_ |dkrd |_ nd |_ 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. rNRGBARGBrz mode mismatchPIF1L)r r )r r r r )loadreadonlyZ_copymode ValueErrorpalette_imageimrcoredrawdraw_inkinkfontmodefillfont)selfrrZblendr./tmp/tmp5hum_rxs/lib64/python/PIL/ImageDraw.py__init__/s2   zImageDraw.__init__cCs"|jsddlm}|j|_|jS)zH Get the current default font. :returns: An image font.r)r)rrZ load_default)rrrrrgetfontYs  zImageDraw.getfontcCs|dkr&|dkr&|jr|j}q|j}n|dk rvt|trFtj||j}|jrjt|tj  rj|jj||j }|j j |}|dk rt|trtj||j}|jrt|tj  r|jj||j }|j j |}||fS)N) rr isinstancestrrZgetcolorrrnumbersNumberrrr)rrrrrr_getinkes"    zImageDraw._getinkrcCs.|j|\}}|dk r*|jj|||||dS)z Draw an arc.N)r'rdraw_arc)rxystartendrwidthrrrrarczsz ImageDraw.arccCs@|j|j|\}}|dkr"|}|dk r<|jj||j|dS)zDraw a bitmap.N)rr'r draw_bitmapr)rr)bitmaprrrrrr/s zImageDraw.bitmapcCs^|j||\}}|dk r,|jj||||d|dk rZ||krZ|dkrZ|jj||||d|dS)z Draw a chord.Nrr)r'rZ draw_chord)rr)r*r+routliner,rrrrchords zImageDraw.chordcCsV|j||\}}|dk r(|jj||d|dk rR||krR|dkrR|jj||d|dS)zDraw an ellipse.Nrr)r'rZ draw_ellipse)rr)rr0r,rrrrellipses zImageDraw.ellipsercs:|j|d}|dk r6|jj||dko6dkr6tdttfsjfddtdtdDxtdtdD]}|}d d|d|f||dffD}|d|dkrqfd d } |d|dkr|dd |dkp |d|dko |dd |dk} |ddd|dddf|ddd|dddfg} | r|dd |dd } } n|dd |dd } } |j| | d | d |dkr| r| ||dd || ||dd g}n&| ||dd || ||dd g}|j ||ddqWdS)z6Draw a line, or a connected sequence of line segments.rNZcurvecs g|]}t||dqS))tuple).0i)r)rr sz"ImageDraw.line..r4rcSs>g|]6\}}tjtj|d|d|d|ddqS)rrih)mathdegreesatan2)r6r*r+rrrr8scsZ|\}}|d8}dd}tdd||tjtj|f||tjtj|ffDS)NZr4rcSs0g|](\}}||dkr tj|ntj|qS)r)r9floorceil)r6pZp_drrrr8sz:ImageDraw.line..coord_at_angle..)r5r9cosradianssin)coordanglexyZdistance)r,rrcoord_at_angles z&ImageDraw.line..coord_at_angler<)r,) r'rZ draw_linesr#listr5rangelenpiesliceline)rr)rr,Zjointrr7pointanglesrGZflippedZcoordsr*r+Z gapCoordsr)r,r)rrOs< $ &&&*zImageDraw.linecCsT|j|j||\}}|dk r0|jj||d|dk rP||krP|jj||ddS)z(Experimental) Draw a shape.Nrr)closer'rZ draw_outline)rshaperr0rrrrrSs zImageDraw.shapecCs^|j||\}}|dk r,|jj||||d|dk rZ||krZ|dkrZ|jj||||d|dS)zDraw a pieslice.Nrr)r'r draw_pieslice)rr)r*r+rr0r,rrrrrNs zImageDraw.pieslicecCs(|j|\}}|dk r$|jj||dS)z#Draw one or more individual pixels.N)r'rZ draw_points)rr)rrrrrrPszImageDraw.pointcCsL|j||\}}|dk r(|jj||d|dk rH||krH|jj||ddS)zDraw a polygon.Nrr)r'rZ draw_polygon)rr)rr0rrrrpolygons zImageDraw.polygoncCst|||}|j|||dS)zDraw a regular polygon.N)!_compute_regular_polygon_verticesrU)rbounding_circlen_sidesrotationrr0r)rrrregular_polygons zImageDraw.regular_polygoncCsV|j||\}}|dk r(|jj||d|dk rR||krR|dkrR|jj||d|dS)zDraw a rectangle.Nrr)r'rdraw_rectangle)rr)rr0r,rrrr rectangles zImageDraw.rectanglec st|dttfr$|\\ \ n |\  |dkrP krh rrj||Sdkrj||Sd}j|\ f dd}dk r|drjj |d |dfdn(jj|d |d fd r rjj |d| |dfdjj| |d |dfddk rkrdkr|ds.jj|d |d dfdjj|d d|d fdsjj |dd |dfdjjd |d |dfddS) zDraw a rounded rectangle.rr4csr:  fddf  fddff}nrt  fddf  fddff}nd  fddf  fddf  fddf  fddff}x:|D]2}|rjj|dfqވjj|fqWdS)NrHihrr<ir)rrTr()rNpartspart) drfull_xfull_yrrr,x0x1y0y1rr draw_corners!s z1ImageDraw.rounded_rectangle..draw_cornersNTrF)r#rKr5r2r\r'rr[)rr)Zradiusrr0r,rrfr) r_rr`rarrr,rbrcrdrerrounded_rectanglesJ     *(,,***zImageDraw.rounded_rectanglecCst|trdnd}||kS)z Draw text.  )r#r$)rtextsplit_characterrrr_multiline_checkXszImageDraw._multiline_checkcCst|trdnd}|j|S)Nrirj)r#r$split)rrkrlrrr_multiline_split^szImageDraw._multiline_splitr3leftFcsj r,j |||| |  SrBjd krBtddkrRjfdd}d  f dd }||}|dk rd}| r| dk r|| n|}|dk r||| ||dn||dS) Nrrz3Embedded color supported only in RGB and RGBA modescsj|\}}|dkr|S|S)N)r')rr)rrrgetinkszImageDraw.text..getinkrc sbj}|dkrrd} }yNj |f||d\}}|d|d|d|df}WnXtk ry$j |||f}Wntk rj }YnXYnX|r|d|d|d|df}|dkrN||jd}}|jd|d?d@|d|jd|d|jdf}jj ||||nj j |||dS)Nrr) directionfeatureslanguage stroke_widthanchorrrrJ) rZgetmask2AttributeErrorZgetmask TypeErrorZgetbandZfillbandsizerZpasterr.) rruZ stroke_offsetrrCmaskoffsetZcolorZcoord2) rvargsrrembedded_colorrsrkwargsrtrrkr)rr draw_textsD  $   $z!ImageDraw.text..draw_text)rr)rN)rmmultiline_textrrr")rr)rkrrrvspacingalignrrrsrtru stroke_fillrr~rrqrrZ stroke_inkr) rvr~rrrrsrrrtrrkr)rrkcs<  "/  zImageDraw.textcCs|dkrtd|dkrd}n*t|dkr4tdn|ddkrHtdg}d }|j|}|jd || d d|}x4|D],}|j|||| | d }|j|t||}qxW|d}|dd kr|t|d|d8}n |ddkr|t|d|8}xt|D]\}}|d }|||}|d d kr8||d8}n|d dkrN||8}|dkrZn4|dkrr||d7}n|dkr||7}ntd|j||f|||||| | | | | d ||7}qWdS)Nttbz/ttb direction is unsupported for multiline textlar4z#anchor must be a 2 character stringrtbz'anchor not supported for multiline textrA)rru)rrrsrtmg@r_rgrpcenterrightz)align must be "left", "center" or "right")rrrsrtrurr) rrMrotextsize textlengthappendmax enumeraterk)rr)rkrrrvrrrrrsrtrurrwidths max_widthlines line_spacingrO line_widthtopidxrpwidth_differencerrrrsb             zImageDraw.multiline_textcCsB|j|r |j|||||||S|dkr0|j}|j|||||S)z*Get the size of a given string, in pixels.N)rmmultiline_textsizer"getsize)rrkrrrrrsrtrurrrr!s zImageDraw.textsizec Csld}|j|} |jd||dd|} x0| D](} |j| ||||||\} } t|| }q,W|t| | |fS)Nrr)rrur)rorrrM)rrkrrrrrsrtrurrrrOrZ line_heightrrrr5s   zImageDraw.multiline_textsizec Cs|j|rtd|r(|jd kr(td|dkr8|j}|r@dn|j}y|j|||||Stk r|j|||||d}|dkr|dS|d SXdS) z@Get the length of a given string, in pixels with 1/64 precision.z&can't measure length of multiline textrrz3Embedded color supported only in RGB and RGBA modesN)rrrsrtrrr)rr)rmrrr"rZ getlengthryr) rrkrrrrsrtrrr{rrrrKs zImageDraw.textlengthc  Cs| r|jd krtd|j|r>|j||||||||| | | S|dkrN|j}t|tjsbtd| rjdn|j} |j || ||| | |} | d|d| d|d| d|d| d |dfS) z2Get the bounding box of a given string, in pixels.rrz3Embedded color supported only in RGB and RGBA modesNz!Only supported for TrueType fontsrrr4rJ)rr) rrrmmultiline_textbboxr"r#rZ FreeTypeFontrZgetbbox)rr)rkrrvrrrrrsrtrurrbboxrrrtextbboxgs.  zImageDraw.textbboxc  CsD|dkrtd|dkrd}n*t|dkr4tdn|ddkrHtdg} d } |j|}|jd || d d|}x6|D].}|j||||| | d }| j|t| |} qxW|d}|dd kr|t|d|d8}n |ddkr|t|d|8}d}xt|D] \}}|d }| | |}|d d krB||d8}n|d dkrX||8}|dkrdn4|dkr|||d7}n|dkr||7}ntd|j||f|||||| | | d }|dkr|}nDt |d |d t |d|dt|d|dt|d|df}||7}qW|dkr@|d |d|d |dfS|S)Nrz/ttb direction is unsupported for multiline textrr4z#anchor must be a 2 character stringrrz'anchor not supported for multiline textrr)rru)rrrsrtrrg@r_rgrprrz)align must be "left", "center" or "right")rrrsrtrurrJ) rrMrorrrrrrmin)rr)rkrrvrrrrrsrtrurrrrrrOrrrrrprZ bbox_linerrrrs|               zImageDraw.multiline_textbbox)N)N)Nr)N)NNr)NNr)NrN)NN)NNr)N)NN)rNN)NNr)rNNr) NNNr3rpNNNrNF) NNNr3rpNNNrNF)Nr3NNNr)Nr3NNNr)NNNNF) NNr3rpNNNrF) NNr3rpNNNrF)__name__ __module__ __qualname__r r"r'r-r/r1r2rOrSrNrPrUrZr\rhrmrorkrrrrrrrrrrr.s *     >     S  d E    #rc Cs*y |j|Stk r$t||SXdS)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)getdrawryr)rrrrrDraws  rc Csbd}| sd|kr8yddlm}Wntk r6YnX|dkrLddlm}|rZ|j|}||fS)a (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. :returns: A (drawing context, drawing resource factory) tuple. NZnicestr) _imagingagg) ImageDraw2)r!r ImportErrorrr)rZhintshandlerrrrr s   rcCsv|j}|\}}y.|||f}t|||kr0dS||||f<Wnttfk rVdSX||fh} t} x| rpt} x| D]\}}x|d|f|d|f||df||dffD]\} } | | f| ks| dks| dkrqy|| | f}Wnttfk rYqX| j| | f|dkr.t|||k}n||ko>||k}|r||| | f<| j| | fqWq~W| } | } qlWdS)a (experimental) Fills a bounded region with a given color. :param image: Target image. :param xy: Seed position (a 2-item coordinate tuple). See :ref:`coordinate-system`. :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. :param thresh: Optional threshold value which specifies a maximum tolerable difference of a pixel value from the 'background' in order for it to be replaced. Useful for filling regions of non-homogeneous, but similar, colors. Nrr)r _color_diffr IndexErrorsetadd)imager)valueZborderZthreshZpixelrErFZ backgroundZedgeZ full_edgeZnew_edgestr?rrrr floodfill$s<   6  rcst|tstd|dkr"tdt|ttfs8tdt|dkrP|^nt|dkrf|\ntdtddfDstd tdkstd d krtd t|ttfstd ddfdddd}|||}fdd|DS)u Generate a list of vertices for a 2D regular polygon. :param bounding_circle: The bounding circle is a tuple defined by a point and radius. The polygon is inscribed in this circle. (e.g. ``bounding_circle=(x, y, r)`` or ``((x, y), r)``) :param n_sides: Number of sides (e.g. ``n_sides=3`` for a triangle, ``6`` for a hexagon) :param rotation: Apply an arbitrary rotation to the polygon (e.g. ``rotation=90``, applies a 90 degree rotation) :return: List of regular polygon vertices (e.g. ``[(25, 50), (50, 50), (50, 25), (25, 25)]``) How are the vertices computed? 1. Compute the following variables - theta: Angle between the apothem & the nearest polygon vertex - side_length: Length of each polygon edge - centroid: Center of bounding circle (1st, 2nd elements of bounding_circle) - polygon_radius: Polygon radius (last element of bounding_circle) - angles: Location of each polygon vertex in polar grid (e.g. A square with 0 degree rotation => [225.0, 315.0, 45.0, 135.0]) 2. For each angle in angles, get the polygon vertex at that angle The vertex is computed using the equation below. X= xcos(φ) + ysin(φ) Y= −xsin(φ) + ycos(φ) Note: φ = angle in degrees x = 0 y = polygon_radius The formula above assumes rotation around the origin. In our case, we are rotating around the centroid. To account for this, we use the formula below X = xcos(φ) + ysin(φ) + centroid_x Y = −xsin(φ) + ycos(φ) + centroid_y zn_sides should be an intrJzn_sides should be an int > 2z!bounding_circle should be a tupler4z[bounding_circle should contain 2D coordinates and a radius (e.g. (x, y, r) or ((x, y), r) )css|]}t|ttfVqdS)N)r#intfloat)r6r7rrr sz4_compute_regular_polygon_vertices..z0bounding_circle should only contain numeric datazBbounding_circle centre should contain 2D coordinates (e.g. (x, y))rz$bounding_circle radius should be > 0z"rotation should be an int or floatcSst|dtjtjd||dtjtjd||ddt|dtjtjd||dtjtjd||ddfS)Nrihrr4)roundr9r@rArB)rPr:centroidrrr_apply_rotations >>z:_compute_regular_polygon_vertices.._apply_rotationcs|dg}|||S)Nrr)rpolygon_radiusrDZ start_point)rrr_compute_polygon_vertexszB_compute_regular_polygon_vertices.._compute_polygon_vertexcSsVg}d|}dd||}x4td|D]&}|j|||7}|dkr(|d8}q(W|S)Nihig?r)rLr)rXrYrQr:Z current_angle_rrr _get_angless  z6_compute_regular_polygon_vertices.._get_anglescsg|]}|qSrr)r6rD)rrrrrr8sz5_compute_regular_polygon_vertices..) r#rrzrrKr5rMallr)rWrXrYrrQr)rrrrrrV\s4)        rVcs<ttr,tfddtdtDStSdS)zJ Uses 1-norm distance to calculate difference between two values. cs g|]}t||qSr)abs)r6r7)color1color2rrr8sz_color_diff..rN)r#r5sumrLrMr)rrr)rrrrs "r)N)NN)Nr)r9r%r!rrrrrrr0ZOutlineryrrrVrrrrr!s" K     8u