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¯ÜãC@sôddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z mZddlmZyddljZWnek r¢dZYnXddlmZmZmZmZmZmZddlmZddlmZmZe j d·krôd d „Z!n"dd lm"Z"e"�s t#‚dZ$dZ%d Z&ej'e(ƒZ)Gdd„de*ƒZ+Gdd„de,ƒZ-e.d»ƒZ/y>ddlm0Z1ee2e1ddƒk�r„ede2e1ddƒ›de›�ƒ‚Wnpek �röZ3zReedƒƒZ1e4e3ƒj5dƒ�rÄe j6de*ƒn e4e3ƒj5dƒ�räe j6e4e3ƒe*ƒ‚WYddZ3[3XnXe7e dƒZ8y ddl9Z9Wnek �r(dZ9YnXdd„Z:dZ;dZdZ?dZ@dZAd ZBdZCdZDd ZEdZFdZGdZHZ;dZId ZJZKdZLdZMZNdZOZPeId!eJd"eLd"eMd#eOd$iZQdZHZ;dZRd ZSdZTdZUdZVdZWdZXd ZYdZZe7e1d%ƒ�rüe1j[Z[e1j\Z\e1j]Z]e1j^Z^e1j_Z_gZ`iZaiZbiZciZdiZeiZfiZge jhd&k�r.d'Zind(Zid¼d½d¾eid+dfeid,dfd¿dÀdÁdÂdÃdÄdÅdÆdÇdÈdÉdÊdËdÌdÍdÎdÏdÐdÑdÒd5œZjd6d7„Zkd8d9d:d;dd?d@dAdBdCg ZldÓZmdGdH„ZndIdJ„ZodKdL„ZpdMdN„ZqdardOdP„ZsdQdR„ZtffdSdT„ZuffdUdV„ZvdWdX„ZwGdYdZ„dZƒZxd[d\„ZyGd]d^„d^ƒZzGd_d`„d`ƒZ{Gdadb„dbƒZ|dcdd„Z}dedf„Z~dÔdgdh„ZdÕdjdk„Z€dÖdldm„Z�d×dndo„Z‚dpdq„Zƒdrds„Z„dÙdÚdÜdÝdßdàdâdãdådædèdédëdìdîdïdñdòdôdõd÷dødúdûdýdþ�d�d�d�d�d�d�d �d �d �d iZ…�de…�deid+f<�de…�deid,f<d†d‡„Z†�dd‰dŠ„Z‡d‹dŒ„Zˆd�dŽ„Z‰d�d�„ZŠd‘d’„Z‹d“d”„ZŒ�dd•d–„Z�d—d˜„ZŽd™dš„Z�d›dœ„Z�d�dž„Z‘dŸd „Z’d¡d¢„Z“d£d¤„Z”d¥d¦„Z•d§d¨„Z–�dd©dª„Z—d«d¬„Z˜d­d®„Z™d¯d°„Zšd±d²„Z›�dd³d´„Zœeœƒej�e1jžƒGdµd¶„d¶eƒZŸdS(éN)ÚCallableÚMutableMapping)ÚPathé)Ú ImageModeÚTiffTagsÚUnidentifiedImageErrorÚ __version__Ú_pluginsÚ_raise_version_warning)Úi32le)Údeferred_errorÚisPathéécCsX|dkrtƒtSddddœ}||kr>tjdtdd�||Stdt›d |›d �ƒ‚dS) NÚPILLOW_VERSIONrré)ÚNORMALÚSEQUENCEÚ CONTAINERzgImage categories are deprecated and will be removed in Pillow 10 (2023-01-02). Use is_animated instead.)Ú stacklevelzmodule 'z' has no attribute 'ú')r r ÚwarningsÚwarnÚDeprecationWarningÚAttributeErrorÚ__name__)ÚnameÚ categories©rú*/tmp/tmp5hum_rxs/lib64/python/PIL/Image.pyÚ __getattr__?s r!)rrc@s eZdZdS)ÚDecompressionBombWarningN)rÚ __module__Ú __qualname__rrrr r"`sr"c@s eZdZdS)ÚDecompressionBombErrorN)rr#r$rrrr r%dsr%ié)Ú_imagingrzUThe _imaging extension was built for another version of Pillow or PIL: Core version: z Pillow version: z'The _imaging C module is not installed.zModule use of pythonz?The _imaging extension was built for another version of Python.zThe _imaging extensionÚpypy_version_infocCs t|dƒS)zÐ Checks if an object is an image object. .. warning:: This function is for internal use only. :param t: object to check if it's an image :returns: True if the object is an image Úim)Úhasattr)Útrrr Ú isImageType•s r,éégà?gð?g@g@ÚDEFAULT_STRATEGYÚlittleú<ú>ú|b1ú|u1Zi4Zf4úu2úi2úu4úi4)Ú1ÚLÚLAÚIÚFÚPÚRGBÚRGBXÚRGBAÚCMYKÚYCbCrÚLABÚHSVzI;16zI;16BzI;16LzI;16SzI;16BSzI;16LSzI;32zI;32BzI;32LzI;32SzI;32BSzI;32LScCsLt|j\}}|dkr.|jd|jdf|fS|jd|jd|f|fSdS)Nrr)Ú _MODE_CONVÚmodeÚsize)r)ÚtypÚextrarrr Ú_conv_type_shape srOr=rFrArIr@r>rHrBrCrErDrGúI;16úI;16LúI;16BcCs tj|ƒjS)a% Gets the "base" mode for given mode. This function returns "L" for images that contain grayscale data, and "RGB" for images that contain color data. :param mode: Input mode. :returns: "L" or "RGB". :exception KeyError: If the input mode was not a standard mode. )rÚgetmodeZbasemode)rKrrr Ú getmodebases rTcCs tj|ƒjS)a  Gets the storage type mode. Given a mode, this function returns a single-layer mode suitable for storing individual bands. :param mode: Input mode. :returns: "L", "I", or "F". :exception KeyError: If the input mode was not a standard mode. )rrSZbasetype)rKrrr Ú getmodetype)s rUcCs tj|ƒjS)a× Gets a list of individual band names. Given a mode, this function returns a tuple containing the names of individual bands (use :py:method:`~PIL.Image.getmodetype` to get the mode used to store each individual band. :param mode: Input mode. :returns: A tuple containing band names. The length of the tuple gives the number of bands in an image of the given mode. :exception KeyError: If the input mode was not a standard mode. )rrSÚbands)rKrrr Úgetmodebandnames5s rWcCsttj|ƒjƒS)zÎ Gets the number of individual bands for this mode. :param mode: Input mode. :returns: The number of bands in this mode. :exception KeyError: If the input mode was not a standard mode. )ÚlenrrSrV)rKrrr Ú getmodebandsDsrYc+Csútdkr dSyddlm}|s"t‚Wntk r8YnXyddlm}|sPt‚Wntk rfYnXyddlm}|s~t‚Wntk r”YnXyddlm}|s¬t‚Wntk rÂYnXyddlm}|sÚt‚Wntk rðYnXdadS)z-Explicitly load standard file format drivers.rN)ÚBmpImagePlugin)ÚGifImagePlugin)ÚJpegImagePlugin)ÚPpmImagePlugin)ÚPngImagePlugin) Ú _initializedÚrZÚAssertionErrorÚ ImportErrorr[r\r]r^)rZr[r\r]r^rrr ÚpreinitUs8          rccCsˆtdkr dSxftD]^}y(tjd|ƒtd|›�tƒtƒgƒWqtk rn}ztjd||ƒWYdd}~XqXqWts|t r„dadSdS)zw Explicitly initializes the Python Imaging Library. This function loads all available file format drivers. rrz Importing %szPIL.zImage: failed to import %s: %sNr) r_r ÚloggerÚdebugÚ __import__ÚglobalsÚlocalsrbÚOPENÚSAVE)ZpluginÚerrr Úinitƒs  $rlcCs¬|dkrf}nt|tƒs|f}y t|}Wntk r>YnX||f||žŽSytt|dƒ}Wn4tk r˜}ztd|›d�ƒ|‚WYdd}~XnX||f||žŽS)NZ_decoderzdecoder z not available)Ú isinstanceÚtupleÚDECODERSÚKeyErrorÚgetattrÚcorerÚOSError)rKÚ decoder_nameÚargsrNÚdecoderrkrrr Ú _getdecoder�s  $rwcCs¬|dkrf}nt|tƒs|f}y t|}Wntk r>YnX||f||žŽSytt|dƒ}Wn4tk r˜}ztd|›d�ƒ|‚WYdd}~XnX||f||žŽS)NZ_encoderzencoder z not available)rmrnÚENCODERSrprqrrrrs)rKÚ encoder_namerurNÚencoderrkrrr Ú _getencoder´s  $r{cCst|tƒr|St|ƒS)N)rmÚ_E)Úvaluerrr Úcoerce_eÏsr~c@s$eZdZdd„Zdd„Zdd„ZdS)r|cCs ||_dS)N)Údata)Úselfrrrr Ú__init__Ôsz _E.__init__cCst|jdt|ƒjfƒS)NÚ__add__)r|rr~)r€Úotherrrr r‚×sz _E.__add__cCst|jdt|ƒjfƒS)NÚ__mul__)r|rr~)r€rƒrrr r„Úsz _E.__mul__N)rr#r$r�r‚r„rrrr r|Ósr|cCsîdg}|t|ƒƒj}yV|\}}}||krD|dkrDt|tjƒrD|dfS||krh|dkrht|tjƒrhd|fSWntk r~YnXyL|\\}}}}}||krÊ|dkrÊt|tjƒrÊ|dkrÊt|tjƒrÊ||fSWntk ràYnXtdƒ‚dS)NÚstubr„gr‚gð?zillegal expression)r|rrmÚnumbersÚNumberÚ TypeErrorÚ ValueError)Úexprr…rÚaÚbÚcÚdrkrrr Ú_getscaleoffsetÞs*     r�c@s®eZdZdZdZdZdZdd„Zdd„Ze dd „ƒZ e d d „ƒZ e d d „ƒZ dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd—dd„Zdd„Zdd„Zd d!„Zd˜d"d#„Zd$d%„Zd&d'„Zd™d)d*„Zdšd,d-„Zd›d.d/„Zd0d1„Zd2d3„Zddded4fd5d6„Z dœd9d:„Z!d;d<„Z"e"Z#d�d=d>„Z$d?d@„Z%dAdB„Z&dždCdD„Z'dEdF„Z(dGdH„Z)dIdJ„Z*dŸdKdL„Z+d dMdN„Z,dOdP„Z-dQdR„Z.dSdT„Z/dUdV„Z0dWdX„Z1dYdZ„Z2d[d\„Z3d¡d]d^„Z4d¢d_d`„Z5d£dadb„Z6d¦dcdd„Z7d§dedf„Z8dgdh„Z9d¨dkdl„Z:d©dndo„Z;dpdq„Zd«dvdw„Z?d¬dxdy„Z@eAd7dddfdzd{„ZBd­d|d}„ZCd~d„ZDd®d€d�„ZEd‚dƒ„ZFd„d…„ZGd†d‡„ZHeIdˆfd‰dŠ„ZJdeAd8dfd‹dŒ„ZKeAd8fd�dŽ„ZLd�d�„ZMd‘d’„ZNd“d”„ZOd•d–„ZPdS)¯ÚImageaD This class represents an image object. To create :py:class:`~PIL.Image.Image` objects, use the appropriate factory functions. There's hardly ever any reason to call the Image constructor directly. * :py:func:`~PIL.Image.open` * :py:func:`~PIL.Image.new` * :py:func:`~PIL.Image.frombytes` NTcCs:d|_d|_d|_d|_i|_d|_d|_d|_d|_dS)Nr`r)rr) r)rKÚ_sizeÚpaletteÚinfoÚ _categoryÚreadonlyÚpyaccessÚ_exif)r€rrr r� szImage.__init__cCs*|dkrtjdtdd�|jSt|ƒ‚dS)NÚcategoryzgImage categories are deprecated and will be removed in Pillow 10 (2023-01-02). Use is_animated instead.r)r)rrrr”r)r€rrrr r!szImage.__getattr__cCs |jdS)Nr)rL)r€rrr Úwidth$sz Image.widthcCs |jdS)Nr)rL)r€rrr Úheight(sz Image.heightcCs|jS)N)r‘)r€rrr rL,sz Image.sizecCs`tƒ}||_|j|_|j|_|jdkrP|jr:|jjƒ|_nddlm}|jƒ|_|j jƒ|_ |S)NrBÚPAr)Ú ImagePalette)rBr›) r�r)rKrLr‘r’Úcopyr`rœr“)r€r)Únewrœrrr Ú_new0s    z Image._newcCs|S)Nr)r€rrr Ú __enter__@szImage.__enter__cGsBt|dƒr8t|ddƒr8t|dƒr(|jƒ|jr8|jjƒd|_dS)NÚfpÚ _exclusive_fpFÚ _close__fp)r*rqr£r¡Úclose)r€rurrr Ú__exit__Cs   zImage.__exit__cCs€y,t|dƒr|jƒ|jr$|jjƒd|_Wn.tk rZ}ztjd|ƒWYdd}~XnXt|ddƒrnd|_t t dƒƒ|_ dS)a¥ Closes the file pointer, if possible. This operation will destroy the image core and release its memory. The image data will be unusable afterward. This function is required to close images that have multiple frames or have not had their file read and closed by the :py:meth:`~PIL.Image.Image.load` method. See :ref:`file-handling` for more information. r£NzError closing: %sÚmapzOperation on closed image) r*r£r¡r¤Ú Exceptionrdrerqr¦r r‰r))r€Úmsgrrr r¤Ks     z Image.closecCs$|jƒ|jjƒ|_d|_d|_dS)Nr)Úloadr)r�r–r•)r€rrr Ú_copyhs z Image._copycCs|jr|jƒn|jƒdS)N)r•rªr©)r€rrr Ú_ensure_mutablens zImage._ensure_mutablecKs|d}|rd|}|s.tj|ƒ\}}tj|ƒn|}|j|ƒsD||}|jƒ| sZ|dkrh|jj|ƒn|j||f|Ž|S)Nr`Ú.ZPPM) ÚtempfileÚmkstempÚosr¤Úendswithr©r)Zsave_ppmÚsave)r€ÚfileÚformatÚoptionsÚsuffixÚfÚfilenamerrr Ú_dumpts  z Image._dumpcCsh|j|jkof|j|jkof|j|jkof|j|jkof|j|jkof|j|jkof|jƒ|jƒkof|jƒ|jƒkS)N)Ú __class__rKrLr“r”r•Ú getpaletteÚtobytes)r€rƒrrr Ú__eq__Šs      z Image.__eq__cCs.d|jj|jj|j|jd|jdt|ƒfS)Nz(<%s.%s image mode=%s size=%dx%d at 0x%X>rr)r¹r#rrKrLÚid)r€rrr Ú__repr__–szImage.__repr__cCsNtjƒ}y|j|dƒWn,tk rD}ztdƒ|‚WYdd}~XnX|jƒS)zZiPython display hook support :returns: png version of the image as bytes ZPNGz!Could not save to PNG for displayN)ÚioÚBytesIOr±r§r‰Úgetvalue)r€rŒrkrrr Ú _repr_png_ s zImage._repr_png_csxddl}i‰t|ƒ\}}|ˆd<|ˆd<dˆd<|jdkrL|jddƒˆd <n |jƒˆd <G‡fd d „d ƒ}|j|ƒ|ƒS) NrÚshapeÚtypestrrÚversionr=Úrawr>rcseZdZ”ZdS)z"Image.__array__..ArrayDataN)rr#r$Ú__array_interface__r)ržrr Ú ArrayData¼srÈ)ÚnumpyrOrKr»Úarray)r€ZdtypeÚnprÃrÄrÈr)ržr Ú __array__¬s   zImage.__array__cCs|j|j|j|jƒ|jƒgS)N)r“rKrLrºr»)r€rrr Ú __getstate__ÁszImage.__getstate__cCsbtj|ƒg|_|\}}}}}||_||_||_tj||ƒ|_|dkrT|rT|j |ƒ|j |ƒdS)Nr>r?rBr›)r>r?rBr›) r�r�Ztiler“rKr‘rrržr)Ú putpaletteÚ frombytes)r€Ústater“rKrLr’rrrr Ú __setstate__Äs   zImage.__setstate__rÆc Gsºt|ƒdkr"t|dtƒr"|d}|dkr8|fkr8|j}|jƒt|j||ƒ}|j|jƒtd|j ddƒ}g}x$|j |ƒ\}}}|j |ƒ|rtPqtW|dkr°t d|›d�ƒ‚dj |ƒS) a  Return image as a bytes object. .. warning:: This method returns the raw image data from the internal storage. For compressed image data (e.g. PNG, JPEG) use :meth:`~.save`, with a BytesIO parameter for in-memory data. :param encoder_name: What encoder to use. The default is to use the standard "raw" encoder. :param args: Extra arguments to the encoder. :returns: A :py:class:`bytes` object. rrrÆir&zencoder error z in tobytesó)rXrmrnrKr©r{Úsetimager)ÚmaxrLÚencodeÚappendÚ RuntimeErrorÚjoin) r€ryrurkÚbufsizerÚlÚsrŽrrr r»Ðs"  z Image.tobytesÚimagecCsz|jƒ|jdkrtdƒ‚|jdƒ}djd|›d|jd›d�jd ƒd|›d |jd ›d�jd ƒd |›d �jd ƒ|dgƒS)a- Returns the image converted to an X11 bitmap. .. note:: This method only works for mode "1" images. :param name: The name prefix to use for the bitmap variables. :returns: A string containing an X11 bitmap. :raises ValueError: If the mode is not "1" r=z not a bitmapZxbmrÒz#define z_width rÚ Úasciiz_height rz static char z _bits[] = { s};)r©rKr‰r»rØrLrÕ)r€rrrrr Útobitmapûs   zImage.tobitmapcGsˆt|ƒdkr"t|dtƒr"|d}|dkr8|fkr8|j}t|j||ƒ}|j|jƒ|j|ƒ}|ddkrptdƒ‚|ddkr„tdƒ‚dS)zç Loads this image with pixel data from a bytes object. This method is similar to the :py:func:`~PIL.Image.frombytes` function, but loads data into this image instead of creating a new image object. rrrÆznot enough image datazcannot decode image dataN) rXrmrnrKrwrÓr)Údecoder‰)r€rrtrurŽrÛrrr rÏs     zImage.frombytescCsJ|jrì|jrì|jjrì|jjƒ\}}|dkrXd}|ddd…|jd<tdd„t|ƒDƒƒ}|jj||ƒ}d |j_d|j_d|jkrÊ|dkrÊt |jdt ƒr®|jj |jdd ƒn|jj |jdƒd|j_ n"d|j_ |jjƒd|d…|j_|j�rFt�r8t�r8|j�r|jSd d lm}|j||jƒ|_|j�r8|jS|jj|jƒSdS)aŠ Allocates storage for the image and loads the pixel data. In normal cases, you don't need to call this method, since the Image class automatically loads an opened image when it is accessed for the first time. If the file associated with the image was opened by Pillow, then this method will close it. The exception to this is if the image has multiple frames, in which case the file will be left open for seek operations. See :ref:`file-handling` for more information. :returns: An image access object. :rtype: :ref:`PixelAccess` or :py:class:`PIL.PyAccess` rErCrNr&Ú transparencycss"|]\}}|ddkr|VqdS)r&rNr)Ú.0Úindexr}rrr ú DszImage.load..rr?r›r)ÚPyAccess)rEr?r›)r)r’ZdirtyÚgetdatar“ÚbytesÚ enumeraterÎÚrawmodermÚintÚputpalettealphaÚputpalettealphasrKrºÚcffiÚUSE_CFFI_ACCESSr–r`råržr•Z pixel_access)r€rKÚarrZpalette_lengthrårrr r©.s4   z Image.loadcCsdS)as Verifies the contents of a file. For data read from a file, this method attempts to determine if the file is broken, without actually decoding the image data. If this method finds any problems, it raises suitable exceptions. If you need to load the image after using this method, you must reopen the image file. Nr)r€rrr Úverify^s z Image.verifyéc:sþ|jƒ|jjdƒdk }| rL|jdkrL|jr8|jj}nd}|dkrL|rLd}| sb||jkrjˆ rj|jƒSˆ�r|dkr€tdƒ‚|jj|ˆƒ}|j |ƒ}|o¦|jj dk�r |jd‰d d „‰|dkrЈˆˆƒ‰n2t |ƒdk�rt ‡‡‡fd d „t d t ˆƒƒDƒƒ‰ˆ|jd<|S|dk�r0|jdk�r0|j|ƒSd} d} |�rô|jdk�rz|dk�rz|j |jj||jdƒƒ} | jd=| S|jdk�r’|dk�r’|jd} t| tƒ�r¶tjdƒd} nÚtƒj tj|jd ƒƒ} |jdk�rJ| j|jƒt| t ƒ�rJd}y| jj| |ƒ} WnBtk �rH}z$t|ƒdk�r.d} n t|ƒ|‚WYdd}~XnX| dk�rZd} n6| jd!| ƒ|d"k�r|| j|ƒ} n | jdƒ} | jd#ƒ} nb|jdk�rô|d$k�rô|jd} d} t| tƒ�rÐ|jj| ƒn$t| tƒ�rì|jj| d ƒntdƒ‚|dk�rž|t k�rž|jj|ƒ}|j |ƒ}ddl!m"}|j"d|jj#dƒƒ|_| �rN|jd=| dk �ršy|jj| |ƒ|jd<Wn(t$k �r˜|jd=tjdƒYnX|S|dk�r¬t%}y|jj||ƒ}Wnhtk �r&y"|jjt&|jƒƒ}|j||ƒ}Wn.t'k �r }ztdƒ|‚WYdd}~XnXYnX|j |ƒ} |dk�rl|t k�rlddl!m"}|j"dt(t dƒƒdƒ| _| �rz| jd=| dk �rú| jdk�rðy| jj| | ƒ| jd<WnDtk �rì}z&| jd=t|ƒdk�rÜtjdƒWYdd}~XnXn | | jd<| S)%a" Returns a converted copy of this image. For the "P" mode, this method translates pixels through the palette. If mode is omitted, a mode is chosen so that all information in the image and the palette can be represented without a palette. The current version supports all possible conversions between "L", "RGB" and "CMYK." The ``matrix`` argument only supports "L" and "RGB". When translating a color image to greyscale (mode "L"), the library uses the ITU-R 601-2 luma transform:: L = R * 299/1000 + G * 587/1000 + B * 114/1000 The default method of converting a greyscale ("L") or "RGB" image into a bilevel (mode "1") image uses Floyd-Steinberg dither to approximate the original image luminosity levels. If dither is :data:`NONE`, all values larger than 127 are set to 255 (white), all other values to 0 (black). To use other thresholds, use the :py:meth:`~PIL.Image.Image.point` method. When converting from "RGBA" to "P" without a ``matrix`` argument, this passes the operation to :py:meth:`~PIL.Image.Image.quantize`, and ``dither`` and ``palette`` are ignored. :param mode: The requested mode. See: :ref:`concept-modes`. :param matrix: An optional conversion matrix. If given, this should be 4- or 12-tuple containing floating point values. :param dither: Dithering method, used when converting from mode "RGB" to "P" or from "RGB" or "L" to "1". Available methods are :data:`NONE` or :data:`FLOYDSTEINBERG` (default). Note that this is not used when ``matrix`` is supplied. :param palette: Palette to use when converting from mode "RGB" to "P". Available palettes are :data:`WEB` or :data:`ADAPTIVE`. :param colors: Number of colors to use for the :data:`ADAPTIVE` palette. Defaults to 256. :rtype: :py:class:`~PIL.Image.Image` :returns: An :py:class:`~PIL.Image.Image` object. ráNrBrCrEr>zillegal conversionrcSsP|d|d|d|d|d|d|dd}tdtdt|ƒƒƒS)Nrrrrgà?éÿ)rÔÚminrê)ÚmÚvrrr Úconvert_transparencyªs<z+Image.convert..convert_transparencycs*g|]"}ˆˆ|d|dd…ˆƒ‘qS)r&r)râÚi)röÚmatrixrárr ú ³sz!Image.convert..rFr=r@zVPalette images with Transparency expressed in bytes should be converted to RGBA imagesTrz2Couldn't allocate a palette color for transparencyz$cannot allocate more than 256 colorsr?r›z.Transparency for P mode should be bytes or int)rœz0Couldn't allocate palette entry for transparencyrñ)r>rC)r=r>r@rC)r>rCrB)r>rCrB)rr)rr)r>rC)rr)r?r›rE))r©r“ÚgetrKr’r�r‰r)Zconvert_matrixrŸrVrXrnÚrangeÚquantizeZconvert_transparentrmrçrrr�rrržrÎÚgetcolorÚstrÚputpixelÚconvertÚgetpixelrìrêrëÚADAPTIVEr`rœrºr§ÚFLOYDSTEINBERGrTrpÚlist)r€rKrøÚditherr’ÚcolorsZhas_transparencyr)ržZtrnsZ delete_trnsÚnew_imr+Ztrns_imÚerrrkrœr)rörørár risÚ*                          "     z Image.convertrrc Csî|jƒ|dkr"t}|jdkr"t}|jdkr@|ttfkr@tdƒ‚|r¦|jƒ|jdkr^tdƒ‚|jdkrz|jdkrztdƒ‚|jjd||jƒ}|j|ƒ}|j j ƒ|_ |S|j|jj |||ƒƒ}d d l m }|jjƒ} |j | |jj| | ƒƒ|_ |S) aÛ Convert the image to 'P' mode with the specified number of colors. :param colors: The desired number of colors, <= 256 :param method: :data:`MEDIANCUT` (median cut), :data:`MAXCOVERAGE` (maximum coverage), :data:`FASTOCTREE` (fast octree), :data:`LIBIMAGEQUANT` (libimagequant; check support using :py:func:`PIL.features.check_feature` with ``feature="libimagequant"``). By default, :data:`MEDIANCUT` will be used. The exception to this is RGBA images. :data:`MEDIANCUT` and :data:`MAXCOVERAGE` do not support RGBA images, so :data:`FASTOCTREE` is used by default instead. :param kmeans: Integer :param palette: Quantize to the palette of given :py:class:`PIL.Image.Image`. :param dither: Dithering method, used when converting from mode "RGB" to "P" or from "RGB" or "L" to "1". Available methods are :data:`NONE` or :data:`FLOYDSTEINBERG` (default). Default: 1 (legacy setting) :returns: A new image NrEzoFast Octree (method == 2) and libimagequant (method == 3) are the only valid methods for quantizing RGBA imagesrBzbad mode for palette imagerCr>z7only RGB or L mode images can be quantized to a paletter)rœ)r©Ú MEDIANCUTrKÚ FASTOCTREEÚ LIBIMAGEQUANTr‰r)rrŸr’r�rür`rœZgetpalettemoderº) r€rÚmethodZkmeansr’rr)rrœrKrrr rü7s0      zImage.quantizecCs|jƒ|j|jjƒƒS)zî Copies this image. Use this method if you wish to paste things into an image, but still retain the original. :rtype: :py:class:`~PIL.Image.Image` :returns: An :py:class:`~PIL.Image.Image` object. )r©rŸr)r�)r€rrr r�zsz Image.copycCs,|dkr|jƒS|jƒ|j|j|j|ƒƒS)a¸ Returns a rectangular region from this image. The box is a 4-tuple defining the left, upper, right, and lower pixel coordinate. See :ref:`coordinate-system`. Note: Prior to Pillow 3.4.0, this was a lazy operation. :param box: The crop rectangle, as a (left, upper, right, lower)-tuple. :rtype: :py:class:`~PIL.Image.Image` :returns: An :py:class:`~PIL.Image.Image` object. N)r�r©rŸÚ_cropr))r€Úboxrrr Úcrop‡s z Image.cropcCsJtttt|ƒƒ\}}}}t||ƒt||ƒf}t|ƒ|j||||fƒS)a] Returns a rectangular region from the core image object im. This is equivalent to calling im.crop((x0, y0, x1, y1)), but includes additional sanity checks. :param im: a core image object :param box: The crop rectangle, as a (left, upper, right, lower)-tuple. :returns: A core image object. )r¦rêÚroundÚabsÚ_decompression_bomb_checkr)r€r)rÚx0Úy0Úx1Úy1Zabsolute_valuesrrr r šs z Image._cropcCsdS)a% Configures the image file loader so it returns a version of the image that as closely as possible matches the given mode and size. For example, you can use this method to convert a color JPEG to greyscale while loading it. If any changes are made, returns a tuple with the chosen ``mode`` and ``box`` with coordinates of the original image within the altered one. Note that this method modifies the :py:class:`~PIL.Image.Image` object in place. If the image has already been loaded, this method has no effect. Note: This method is not implemented for most images. It is currently implemented only for JPEG and MPO images. :param mode: The requested mode. :param size: The requested size. Nr)r€rKrLrrr Údraft®sz Image.draftcCs*|dkr |}|jƒ|j|jj||dƒƒS)Nr)r©rŸr)Úexpand)r€ZxmarginZymarginrrr Ú_expandÄsz Image._expandcCs¨ddlm}|jƒt|tƒr$|ƒ}t|dƒs6tdƒ‚t||jƒ}|jj dksR|rd|j |j |jƒƒSg}x2t |jj ƒD]"}|j |j |j |jj|ƒƒƒƒqvWt|j|ƒS)zé Filters this image using the given filter. For a list of available filters, see the :py:mod:`~PIL.ImageFilter` module. :param filter: Filter kernel. :returns: An :py:class:`~PIL.Image.Image` object.r)Ú ImageFilterÚfilterz>filter argument should be ImageFilter.Filter instance or class)r`rr©rmrr*rˆZMultibandFilterr)rVrŸrrûrÖÚgetbandÚmergerK)r€rrZ multibandÚimsr�rrr rÊs    "z Image.filtercCstj|jƒjS)zä Returns a tuple containing the name of each band in this image. For example, ``getbands`` on an RGB image returns ("R", "G", "B"). :returns: A tuple containing band names. :rtype: tuple )rrSrKrV)r€rrr ÚgetbandsæszImage.getbandscCs|jƒ|jjƒS)aQ Calculates the bounding box of the non-zero regions in the image. :returns: The bounding box is returned as a 4-tuple defining the left, upper, right, and lower pixel coordinate. See :ref:`coordinate-system`. If the image is completely empty, this method returns None. )r©r)Úgetbbox)r€rrr r ðs z Image.getbboxcCsl|jƒ|jdkr`|jjƒ}g}x*tdƒD]}||r*|j|||fƒq*Wt|ƒ|kr\dS|S|jj|ƒS)aó Returns a list of colors used in this image. The colors will be in the image's mode. For example, an RGB image will return a tuple of (red, green, blue) color values, and a P image will return the index of the color in the palette. :param maxcolors: Maximum number of colors. If this number is exceeded, this method returns None. The default limit is 256 colors. :returns: An unsorted list of (count, pixel) values. r=r>rBrñN)r=r>rB)r©rKr)Ú histogramrûrÖrXÚ getcolors)r€Z maxcolorsÚhÚoutr÷rrr r"ÿs   zImage.getcolorscCs"|jƒ|dk r|jj|ƒS|jS)aå Returns the contents of this image as a sequence object containing pixel values. The sequence object is flattened, so that values for line one follow directly after the values of line zero, and so on. Note that the sequence object returned by this method is an internal PIL data type, which only supports certain sequence operations. To convert it to an ordinary sequence (e.g. for printing), use ``list(im.getdata())``. :param band: What band to return. The default is to return all bands. To return a single band, pass in the index value (e.g. 0 to get the "R" band from an "RGB" image). :returns: A sequence-like object. N)r©r)r)r€Úbandrrr ræs z Image.getdatacCsV|jƒ|jjdkrLg}x*t|jjƒD]}|j|jj|ƒjƒƒq&Wt|ƒS|jjƒS)a& Gets the the minimum and maximum pixel values for each band in the image. :returns: For a single-band image, a 2-tuple containing the minimum and maximum pixel value. For a multi-band image, a tuple containing one 2-tuple for each band. r)r©r)rVrûrÖrÚ getextremarn)r€Úextremar÷rrr r&0s  zImage.getextremacsLdd„‰‡‡fdd„‰tdkr,tjdƒiStj|ƒ}ˆ|jƒˆ|ƒiSdS)NcSs|jdƒdS)Nú}r)Úsplit)Útagrrr Úget_nameCszImage._getxmp..get_namecs¢‡fdd„|jjƒDƒ}t|ƒ}|r‚xx|D]R}ˆ|jƒ}ˆ|ƒ}||krtt||tƒsd||g||<||j|ƒq*|||<q*Wn|r˜|jrž|j|d<n|jS|S)Ncsi|]\}}|ˆ|ƒ“qSrr)râÚkrõ)r+rr ú Gsz4Image._getxmp..get_value..Útext)ZattribÚitemsrr*rmrÖr.)Úelementr}ÚchildrenÚchildrZ child_value)r+Ú get_valuerr r3Fs    z Image._getxmp..get_valuez5XMP data cannot be read without defusedxml dependency)Ú ElementTreerrÚ fromstringr*)r€Úxmp_tagsÚrootr)r+r3r Ú_getxmpBs  z Image._getxmpcCsÖ|jdkrtƒ|_|jjdƒ}|dkr€d|jkrVtjdj|jdjdƒdd…ƒƒ}n*t|dƒr€|j j |j_ |jj |j |j jƒ|dk r”|jj|ƒd|jkrÐ|jjdƒ}|rÐtjd |ƒ}|rÐt|d ƒ|jd<|jS) NZexifzRaw profile type exifr`rÝrÚtag_v2izXML:com.adobe.xmpztiff:Orientation="([0-9])"r)r—ÚExifr“rúrçÚfromhexrØr)r*r9Ú_endianÚendianÚ load_from_fpr¡Ú_offsetr©ÚreÚsearchrê)r€Z exif_infor6Úmatchrrr Úgetexifas&   "      z Image.getexifcCs|jƒ|jjS)zr Returns a capsule that points to the internal image memory. :returns: A capsule object. )r©r)Úptr)r€rrr Úgetim{sz Image.getimc Cs0|jƒyt|jjƒƒStk r*dSXdS)z  Returns the image palette as a list. :returns: A list of color values [r, g, b, ...], or None if the image has no palette. N)r©rr)rºr‰)r€rrr rº…s zImage.getpalettecCs&|jƒ|jr|jj|ƒS|jj|ƒS)a  Returns the pixel value at a given position. :param xy: The coordinate, given as (x, y). See :ref:`coordinate-system`. :returns: The pixel value. If the image is a multi-layer image, this method returns a tuple. )r©r–rr))r€Úxyrrr r“s  zImage.getpixelcCs&|jƒ|jjƒ\}}t|ƒt|ƒfS)z¸ Get projection to x and y axes :returns: Two sequences, indicating where there are non-zero pixels along the X-axis and the Y-axis, respectively. )r©r)Ú getprojectionr)r€ÚxÚyrrr rG¢szImage.getprojectioncCsT|jƒ|r$|jƒ|jjd|jƒS|jdkrJ|dkr>|jƒ}|jj|ƒS|jjƒS)ae Returns a histogram for the image. The histogram is returned as a list of pixel counts, one for each pixel value in the source image. If the image has more than one band, the histograms for all bands are concatenated (for example, the histogram for an "RGB" image contains 768 values). A bilevel image (mode "1") is treated as a greyscale ("L") image by this method. If a mask is provided, the method returns a histogram for those parts of the image where the mask image is non-zero. The mask image must have the same size as the image, and be either a bi-level image (mode "1") or a greyscale image ("L"). :param mask: An optional mask. :param extrema: An optional tuple of manually-specified extrema. :returns: A list containing pixel counts. rr@rAN)rr)r@rA)r©r)r!rKr&)r€Úmaskr'rrr r!®s  zImage.histogramcCsT|jƒ|r$|jƒ|jjd|jƒS|jdkrJ|dkr>|jƒ}|jj|ƒS|jjƒS)ah Calculates and returns the entropy for the image. A bilevel image (mode "1") is treated as a greyscale ("L") image by this method. If a mask is provided, the method employs the histogram for those parts of the image where the mask image is non-zero. The mask image must have the same size as the image, and be either a bi-level image (mode "1") or a greyscale image ("L"). :param mask: An optional mask. :param extrema: An optional tuple of manually-specified extrema. :returns: A float value representing the image entropy rr@rAN)rr)r@rA)r©r)ÚentropyrKr&)r€rJr'rrr rKÌs  z Image.entropycCs t|ƒr|dkr|}d}|dkr$d }t|ƒdkr|t|ƒr@|j}nt|ƒrP|j}ntdƒ‚||d|d|d|df7}t|tƒr¢ddlm}|j||j ƒ}nBt|ƒrä|j ƒ|j |j krÞ|j dksÒ|j d krÞ|j |j ƒ}|j }|j ƒ|�r|j ƒ|j j|||j ƒn|j j||ƒdS) a’ Pastes another image into this image. The box argument is either a 2-tuple giving the upper left corner, a 4-tuple defining the left, upper, right, and lower pixel coordinate, or None (same as (0, 0)). See :ref:`coordinate-system`. If a 4-tuple is given, the size of the pasted image must match the size of the region. If the modes don't match, the pasted image is converted to the mode of this image (see the :py:meth:`~PIL.Image.Image.convert` method for details). Instead of an image, the source can be a integer or tuple containing pixel values. The method then fills the region with the given color. When creating RGB images, you can also use color strings as supported by the ImageColor module. If a mask is given, this method updates only the regions indicated by the mask. You can use either "1", "L" or "RGBA" images (in the latter case, the alpha band is used as mask). Where the mask is 255, the given image is copied as is. Where the mask is 0, the current value is preserved. Intermediate values will mix the two images together, including their alpha channels if they have them. See :py:meth:`~PIL.Image.Image.alpha_composite` if you want to combine images with respect to their alpha channels. :param im: Source image or pixel value (integer or tuple). :param box: An optional 4-tuple giving the region to paste into. If a 2-tuple is used instead, it's treated as the upper left corner. If omitted or None, the source is pasted into the upper left corner. If an image is given as the second argument and there is no third, the box defaults to (0, 0), and the second argument is interpreted as a mask image. :param mask: An optional mask image. Nrrz,cannot determine region size; use 4-item boxr)Ú ImageColorrCrEÚRGBa)rr)rErM)r,rXrLr‰rmrþr`rLrýrKr©rr)r«Úpaste)r€r)rrJrLrLrrr rNæs4( $    z Image.pastecCsôt|ttfƒstdƒ‚t|ttfƒs,tdƒ‚t|ƒd kr@tdƒ‚t|ƒdksTtdƒ‚t|ƒdkrhtdƒ‚t|ƒdkr~||j}|d |jkr’|}n |j|ƒ}||d|j|d |j f}|d |jkrÐ|}n |j|ƒ}t ||ƒ}|j ||ƒd S)a-'In-place' analog of Image.alpha_composite. Composites an image onto this image. :param im: image to composite over this one :param dest: Optional 2 tuple (left, top) specifying the upper left corner in this (destination) image. :param source: Optional 2 (left, top) tuple for the upper left corner in the overlay source image, or 4 tuple (left, top, right, bottom) for the bounds of the source rectangle Performance Note: Not currently implemented in-place in the core layer. zSource must be a tuplezDestination must be a tuplerr&zSource must be a 2 or 4-tuplezDestination must be a 2-tuplerzSource must be non-negativerN)rr&)rr)rr) rmrrnr‰rXrórLrr™ršÚalpha_compositerN)r€r)ÚdestÚsourceZoverlayrZ backgroundÚresultrrr rO6s*         zImage.alpha_compositecs’|jƒtˆtƒrˆj|ƒStˆƒrl|jdkrNtˆƒ\}}|j|jj ||ƒƒS‡fdd„t dƒDƒ|jj ‰|jdkr~t dƒ‚|j|jjˆ|ƒƒS) aÝ Maps this image through a lookup table or function. :param lut: A lookup table, containing 256 (or 65536 if self.mode=="I" and mode == "L") values per band in the image. A function can be used instead, it should take a single argument. The function is called once for each possible pixel value, and the resulting table is applied to all bands of the image. It may also be an :py:class:`~PIL.Image.ImagePointHandler` object:: class Example(Image.ImagePointHandler): def point(self, data): # Return result :param mode: Output mode (default is same as input). In the current version, this can only be used if the source image has mode "L" or "P", and the output has mode "1" or the source image mode is "I" and the output mode is "L". :returns: An :py:class:`~PIL.Image.Image` object. r@úI;16rAcsg|] }ˆ|ƒ‘qSrr)râr÷)Úlutrr rùŠszImage.point..rñz+point operation not supported for this mode)r@rSrA) r©rmÚImagePointHandlerÚpointÚcallablerKr�rŸr)Zpoint_transformrûrVr‰)r€rTrKÚscaleÚoffsetr)rTr rVds     z Image.pointc Csb|jƒ|jd kr¼y|t|jƒd}y|jj|ƒWnHttfk rz}z(|jj|ƒ}|jd krdt|‚||_WYdd}~XnXd|_|jj|_Wn,t k rº}ztdƒ|‚WYdd}~XnX|jd krÌd}nd}t |ƒ�r|jdk�rîtdƒ‚|j ƒ|jd k�rN|jd ƒ}n@y|jj ||ƒWn(ttfk �rHt d |j|ƒ}YnXdS|jj|j|ƒdS)az Adds or replaces the alpha layer in this image. If the image does not have an alpha layer, it's converted to "LA" or "RGBA". The new layer must be either "L" or "1". :param alpha: The new alpha layer. This can either be an "L" or "1" image having the same size as this image, or an integer or other color value. r?r›rEÚANzillegal image moderrr=r>)r?r›rE)r?r›rE)r?r›)r=r>)r«rKrTr)Zsetmoderr‰rr–rpr,r©ZfillbandržrLZputband)r€ÚalpharKrkr)r%rrr Úputalpha’s<         zImage.putalphaçð?çcCs|jƒ|jj|||ƒdS)a Copies pixel data to this image. This method copies data from a sequence object into the image, starting at the upper left corner (0, 0), and continuing until either the image or the sequence ends. The scale and offset values are used to adjust the sequence values: **pixel = value*scale + offset**. :param data: A sequence object. :param scale: An optional scale value. The default is 1.0. :param offset: An optional offset value. The default is 0.0. N)r«r)Úputdata)r€rrXrYrrr r_Ès z Image.putdatarCcCsˆddlm}|jd krtdƒ‚t||jƒr<|j|j|jƒ}nt|tƒsNt|ƒ}|j||ƒ}d|jkrhdnd|_||_d |j_|j ƒd S) as Attaches a palette to this image. The image must be a "P", "PA", "L" or "LA" image. The palette sequence must contain at most 256 colors, made up of one integer value for each channel in the raw mode. For example, if the raw mode is "RGB", then it can contain at most 768 values, made up of red, green and blue values for the corresponding pixel index in the 256 colors. If the raw mode is "RGBA", then it can contain at most 1024 values, containing red, green, blue and alpha values. Alternatively, an 8-bit string may be used instead of an integer sequence. :param data: A palette sequence (either a list or a string). :param rawmode: The raw mode of the palette. Either "RGB", "RGBA", or a mode that can be transformed to "RGB" (e.g. "R", "BGR;15", "RGBA;L"). r)rœr>r?rBr›zillegal image moderZrCN)r>r?rBr›) r`rœrKr‰rmrÆrér’rçr©)r€rrérœr’rrr rÎÙs     zImage.putpalettecCsj|jr|jƒ|jƒ|jr*|jj||ƒS|jdkr\t|ttfƒr\t |ƒdkr\|j j ||ƒ}|j j||ƒS)aÎ Modifies the pixel at the given position. The color is given as a single numerical value for single-band images, and a tuple for multi-band images. In addition to this, RGB and RGBA tuples are accepted for P images. Note that this method is relatively slow. For more extensive changes, use :py:meth:`~PIL.Image.Image.paste` or the :py:mod:`~PIL.ImageDraw` module instead. See: * :py:meth:`~PIL.Image.Image.paste` * :py:meth:`~PIL.Image.Image.putdata` * :py:mod:`~PIL.ImageDraw` :param xy: The pixel coordinate, given as (x, y). See :ref:`coordinate-system`. :param value: The pixel value. rBrr&)rr&) r•rªr©r–rÿrKrmrrnrXr’rýr))r€rFr}rrr rÿûs  zImage.putpixelc Cs&ddlm}|jdkrtdƒ‚|dkrd|jdkrN|jƒ|jjdƒdd…}ntd d „tdƒDƒƒ}d }d gd }x8t |ƒD],\}}|||d|dd…7}|||<q|Wt|ƒ}|j ƒ} d| _|jd|dd�| _ | jj d| j j ƒƒ| jdƒ} |dt|ƒd} | j | ƒ|jd|d�| _ | S)ae Rewrites the image to reorder the palette. :param dest_map: A list of indexes into the original palette. e.g. ``[1,0]`` would swap a two item palette, and ``list(range(256))`` is the identity transform. :param source_palette: Bytes or None. :returns: An :py:class:`~PIL.Image.Image` object. r)rœr>rBzillegal image modeNrCicss|]}|dVqdS)rNr)râr÷rrr rä6sz&Image.remap_palette..rÒrrñr)r’zRGB;Ló)r>rB)r`rœrKr‰r©r)rºÚ bytearrayrûrèr�r’rÎr»rrX) r€Zdest_mapZsource_paletterœZ palette_bytesZ new_positionsr÷Z oldPositionZmapping_paletteZm_imZnew_palette_bytesrrr Ú remap_palette!s.       zImage.remap_palettec Cs°t|d}|d|d|d}|d|d|d}||}||}tdt|d|ƒƒtdt|d|ƒƒt|jdtj|d|ƒƒt|jdtj|d|ƒƒfS)z€Expands the box so it includes adjacent pixels that may be used by resampling with the given resampling filter. gà?rrrr)Ú_filters_supportrÔrêrórLÚmathÚceil) r€rLÚresamplerZfilter_supportZscale_xZscale_yZ support_xZ support_yrrr Ú _get_safe_boxgs zImage._get_safe_boxc Csp|dkr d|jk}|rtnt}n||ttttttfkrœd|›d�}dd„tdftdftd ftd ftd ftd ffDƒ}t|d dj|dd…ƒd|dƒ‚|dk r´|dkr´tdƒ‚t |ƒ}|dkrÐd |j }nt |ƒ}|j |koî|d!|j k�rú|j ƒS|jd"k�r t}|jd#k�rP|tk�rP|j dddœ|jƒ}|j |||ƒ}|j |jƒS|jƒ|dk �rZ|tk�rZt|d|d|d|ƒ�p�d} t|d|d|d|ƒ�p¶d} | dk�sÌ| dk�rZ|j|||ƒ} | | f} t|jƒ�rþ|j| | d�}ntj|| | d�}|d| d| |d| d| |d| d| |d| d| f}|j|jj |||ƒƒS)$aL Returns a resized copy of this image. :param size: The requested size in pixels, as a 2-tuple: (width, height). :param resample: An optional resampling filter. This can be one of :py:data:`PIL.Image.NEAREST`, :py:data:`PIL.Image.BOX`, :py:data:`PIL.Image.BILINEAR`, :py:data:`PIL.Image.HAMMING`, :py:data:`PIL.Image.BICUBIC` or :py:data:`PIL.Image.LANCZOS`. If the image has mode "1" or "P", it is always set to :py:data:`PIL.Image.NEAREST`. If the image mode specifies a number of bits, such as "I;16", then the default filter is :py:data:`PIL.Image.NEAREST`. Otherwise, the default filter is :py:data:`PIL.Image.BICUBIC`. See: :ref:`concept-filters`. :param box: An optional 4-tuple of floats providing the source image region to be scaled. The values must be within (0, 0, width, height) rectangle. If omitted or None, the entire source is used. :param reducing_gap: Apply optimization by resizing the image in two steps. First, reducing the image by integer times using :py:meth:`~PIL.Image.Image.reduce`. Second, resizing using regular resampling. The last step changes size no less than by ``reducing_gap`` times. ``reducing_gap`` may be None (no first step is performed) or should be greater than 1.0. The bigger ``reducing_gap``, the closer the result to the fair resampling. The smaller ``reducing_gap``, the faster resizing. With ``reducing_gap`` greater or equal to 3.0, the result is indistinguishable from fair resampling in most cases. The default value is None (no optimization). :returns: An :py:class:`~PIL.Image.Image` object. Nú;zUnknown resampling filter (z).cSs g|]}dj|d|dƒ‘qS)z{} ({})rr)r³)rârrrr rù¢sz Image.resize..z Image.NEARESTz Image.LANCZOSzImage.BILINEARz Image.BICUBICz Image.BOXz Image.HAMMINGz Use z, rz or gð?z#reducing_gap must be 1.0 or greaterrr=rBr?rEÚLarM)r?rErr)réÿÿÿÿrj)rr)rr)r=rB)r?rE)rKÚNEARESTÚBICUBICÚBILINEARÚLANCZOSÚBOXÚHAMMINGr‰rØrnrLr�rÚresizer©rêrgrWÚreducer�rŸr)) r€rLrfrÚ reducing_gapZ type_specialÚmessageÚfiltersr)Zfactor_xZfactor_yZ reduce_boxÚfactorrrr rqxsV#  (   && z Image.resizecCs¤t|ttfƒs||f}|dkr*d |j}nt|ƒ}|d krP|d |jkrP|jƒS|jd krˆ|jdddœ|jƒ}|j||ƒ}|j|jƒS|jƒ|j |j j||ƒƒS) a! Returns a copy of the image reduced ``factor`` times. If the size of the image is not dividable by ``factor``, the resulting size will be rounded up. :param factor: A greater than 0 integer or tuple of two integers for width and height separately. :param box: An optional 4-tuple of ints providing the source image region to be reduced. The values must be within ``(0, 0, width, height)`` rectangle. If omitted or ``None``, the entire source is used. Nrrr?rErirM)r?rE)rr)rr)rr)r?rE) rmrrnrLr�rKrrrr©rŸr))r€rvrr)rrr rrÚs     z Image.reducecCs,|d}|p|s`|dkr |jƒS|dkr2|jtƒS|dkr`|sJ|j|jkr`|j|dkrZtntƒS|j\}}|dkrxd} n|} |dkr–|d|df} n|} tj |ƒ }t tj |ƒdƒt tj |ƒdƒd t tj |ƒ dƒt tj |ƒdƒd g} d d „} | | d | d| d  | d | ƒ\| d <| d<| d | d7<| d| d 7<|�rg} g}xJd|df||fd|ffD].\}}| ||| ƒ\}}| j |ƒ|j |ƒ�qtWtjt| ƒƒtjt| ƒƒ}tjt|ƒƒtjt|ƒƒ}| || d|| d| ƒ\| d <| d<||}}|j||ft| ||d�S)a‰ Returns a rotated copy of this image. This method returns a copy of this image, rotated the given number of degrees counter clockwise around its centre. :param angle: In degrees counter clockwise. :param resample: An optional resampling filter. This can be one of :py:data:`PIL.Image.NEAREST` (use nearest neighbour), :py:data:`PIL.Image.BILINEAR` (linear interpolation in a 2x2 environment), or :py:data:`PIL.Image.BICUBIC` (cubic spline interpolation in a 4x4 environment). If omitted, or if the image has mode "1" or "P", it is set to :py:data:`PIL.Image.NEAREST`. See :ref:`concept-filters`. :param expand: Optional expansion flag. If true, expands the output image to make it large enough to hold the entire rotated image. If false or omitted, make the output image the same size as the input image. Note that the expand flag assumes rotation around the center and no translation. :param center: Optional center of rotation (a 2-tuple). Origin is the upper left corner. Default is the center of the image. :param translate: An optional post-rotate translation (a 2-tuple). :param fillcolor: An optional color for area outside the rotated image. :returns: An :py:class:`~PIL.Image.Image` object. g€v@ré´éZéNg@égc Ss8|\}}}}}}||||||||||fS)Nr) rHrIrør‹rŒr�rŽrkr¶rrr Ú transformQszImage.rotate..transformrrr-)Ú fillcolor)rxry)rr)rr)r�Ú transposeÚ ROTATE_180r™ršÚ ROTATE_90Ú ROTATE_270rLrdÚradiansrÚcosÚsinrÖrerÔÚfloorrór{ÚAFFINE)r€ZanglerfrÚcenterÚ translater|Úwr#Z post_transZ rotn_centerrør{ZxxÚyyrHrIÚnwZnhrrr ÚrotateûsN"   2" , z Image.rotatec Ks–d}d}t|tƒr t|ƒ}d}n>t|ƒr2|}d}n,|tjkr^y tjj}Wntk r\YnX| r~t|dƒr~t|j ƒr~|j }|j ƒ|j ddƒ}||_ f|_ tƒtjj|ƒdjƒ}|�s|tkrÌtƒy t|}Wn4tk �r }ztd|›�ƒ|‚WYdd}~XnX|jƒtk�r"tƒ|�r6t|jƒ} n t|jƒ} |�rp|jd dƒ�rdtj|d ƒ}n tj|d ƒ}z| |||ƒWd|�r�|jƒXdS) a† Saves this image under the given filename. If no format is specified, the format to use is determined from the filename extension, if possible. Keyword options can be used to provide additional instructions to the writer. If a writer doesn't recognise an option, it is silently ignored. The available options are described in the :doc:`image format documentation <../handbook/image-file-formats>` for each writer. You can use a file object instead of a filename. In this case, you must always specify the format. The file object must implement the ``seek``, ``tell``, and ``write`` methods, and be opened in binary mode. :param fp: A filename (string), pathlib.Path object or file object. :param format: Optional format override. If omitted, the format to use is determined from the filename extension. If a file object was used instead of a filename, this parameter should always be used. :param params: Extra parameters to the image writer. :returns: None :exception ValueError: If the output format could not be determined from the file name. Use the format option to solve this. :exception OSError: If the file could not be written. The file may have been created, and may contain partial data. r`FTrÚsave_allrzunknown file extension: NrÖzr+bzw+b)rmrrþrÚsysÚstdoutÚbufferrr*rr«ÚpopZ encoderinfoZ encoderconfigrcr¯ÚpathÚsplitextÚlowerÚ EXTENSIONrlrpr‰ÚupperrjÚSAVE_ALLrúÚbuiltinsÚopenr¤) r€r¡r³Úparamsr·Zopen_fprŒÚextrkZ save_handlerrrr r±nsR     "  z Image.savecCs|dkr t‚dS)a0 Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an ``EOFError`` exception. When a sequence file is opened, the library automatically seeks to frame 0. See :py:meth:`~PIL.Image.Image.tell`. If defined, :attr:`~PIL.Image.Image.n_frames` refers to the number of available frames. :param frame: Frame number, starting at 0. :exception EOFError: If the call attempts to seek beyond the end of the sequence. rN)ÚEOFError)r€Úframerrr ÚseekÆsz Image.seekcCs&|dk rtjdtƒt|||d�dS)aÙ Displays this image. This method is mainly intended for debugging purposes. This method calls :py:func:`PIL.ImageShow.show` internally. You can use :py:func:`PIL.ImageShow.register` to override its default behaviour. The image is first saved to a temporary file. By default, it will be in PNG format. On Unix, the image is then opened using the **display**, **eog** or **xv** utility, depending on which one can be found. On macOS, the image is opened with the native Preview application. On Windows, the image is opened with the standard PNG display utility. :param title: Optional title to use for the image window, where possible. Nz}The command parameter is deprecated and will be removed in Pillow 9 (2022-01-02). Use a subclass of ImageShow.Viewer instead.)ÚtitleÚcommand)rrrÚ_show)r€ržrŸrrr ÚshowÛs z Image.showcCs:|jƒ|jjdkr |jƒg}nt|j|jjƒƒ}t|ƒS)aÏ Split this image into individual bands. This method returns a tuple of individual image bands from an image. For example, splitting an "RGB" image creates three new images each containing a copy of one of the original bands (red, green, blue). If you need only one band, :py:meth:`~PIL.Image.Image.getchannel` method can be more convenient and faster. :returns: A tuple containing bands. r)r©r)rVr�r¦rŸr)rn)r€rrrr r)øs   z Image.splitcCsl|jƒt|tƒrZy|jƒj|ƒ}Wn4tk rX}ztd|›d�ƒ|‚WYdd}~XnX|j|jj|ƒƒS)a@ Returns an image containing a single channel of the source image. :param channel: What channel to return. Could be index (0 for "R" channel of "RGB") or channel name ("A" for alpha channel of "RGBA"). :returns: An image in "L" mode. .. versionadded:: 4.3.0 zThe image has no channel "ú"N) r©rmrþrrãr‰rŸr)r)r€Zchannelrkrrr Ú getchannel s  $zImage.getchannelcCsdS)zô Returns the current frame number. See :py:meth:`~PIL.Image.Image.seek`. If defined, :attr:`~PIL.Image.Image.n_frames` refers to the number of available frames. :returns: Frame number, starting with 0. rr)r€rrr Útell" s z Image.tellg@csttj|ƒ\‰‰ˆ|jkr(ˆ|jkr(dSdd„}|j|j‰ˆˆˆkrd|ˆˆ‡‡fdd„d�‰n|ˆˆ‡‡fdd„d�‰ˆˆf}d}|dk rÂ|jd|d||d |fƒ}|dk rÂ|d }|j|krö|j||||d �}|j|_||_ |jj |_ d|_ d|_ dS) a. Make this image into a thumbnail. This method modifies the image to contain a thumbnail version of itself, no larger than the given size. This method calculates an appropriate thumbnail size to preserve the aspect of the image, calls the :py:meth:`~PIL.Image.Image.draft` method to configure the file reader (where applicable), and finally resizes the image. Note that this function modifies the :py:class:`~PIL.Image.Image` object in place. If you need to use the full resolution image as well, apply this method to a :py:meth:`~PIL.Image.Image.copy` of the original image. :param size: Requested size. :param resample: Optional resampling filter. This can be one of :py:data:`PIL.Image.NEAREST`, :py:data:`PIL.Image.BOX`, :py:data:`PIL.Image.BILINEAR`, :py:data:`PIL.Image.HAMMING`, :py:data:`PIL.Image.BICUBIC` or :py:data:`PIL.Image.LANCZOS`. If omitted, it defaults to :py:data:`PIL.Image.BICUBIC`. (was :py:data:`PIL.Image.NEAREST` prior to version 2.5.0). See: :ref:`concept-filters`. :param reducing_gap: Apply optimization by resizing the image in two steps. First, reducing the image by integer times using :py:meth:`~PIL.Image.Image.reduce` or :py:meth:`~PIL.Image.Image.draft` for JPEG images. Second, resizing using regular resampling. The last step changes size no less than by ``reducing_gap`` times. ``reducing_gap`` may be None (no first step is performed) or should be greater than 1.0. The bigger ``reducing_gap``, the closer the result to the fair resampling. The smaller ``reducing_gap``, the faster resizing. With ``reducing_gap`` greater or equal to 3.0, the result is indistinguishable from fair resampling in most cases. The default value is 2.0 (very close to fair resampling while still being faster in many cases). :returns: None NcSs tttj|ƒtj|ƒ|d�dƒS)N)Úkeyr)rÔrórdr„re)Únumberr¥rrr Ú round_aspectX sz%Image.thumbnail..round_aspectcstˆ|ˆƒS)N)r)Ún)ÚaspectrIrr Ú^ sz!Image.thumbnail..)r¥cs|dkr dStˆˆ|ƒS)Nr)r)r¨)r©rHrr rªa srr)rrs) r¦rdr„r™ršrrLrqr)r‘rKr•r–)r€rLrfrsr§rÚresr)r)r©rHrIr Ú thumbnail- s,'     zImage.thumbnailc Cs |jd kr@|tkr@|jdddœ|jƒj||||||ƒj|jƒSt|tƒr\|j||||d�St|dƒrr|jƒ\}}|dkr‚td ƒ‚t |j||ƒ}|jd kr¬|j r¬|j j ƒ|_ |j j ƒ|_ |t krìxF|D] \}} |j||t| ||dkƒqÆWn|jd ||||||dkƒ|S)at Transforms this image. This method creates a new image with the given size, and the same mode as the original, and copies data to the new image using the given transform. :param size: The output size. :param method: The transformation method. This is one of :py:data:`PIL.Image.EXTENT` (cut out a rectangular subregion), :py:data:`PIL.Image.AFFINE` (affine transform), :py:data:`PIL.Image.PERSPECTIVE` (perspective transform), :py:data:`PIL.Image.QUAD` (map a quadrilateral to a rectangle), or :py:data:`PIL.Image.MESH` (map a number of source quadrilaterals in one operation). It may also be an :py:class:`~PIL.Image.ImageTransformHandler` object:: class Example(Image.ImageTransformHandler): def transform(self, size, data, resample, fill=1): # Return result It may also be an object with a ``method.getdata`` method that returns a tuple supplying new ``method`` and ``data`` values:: class Example: def getdata(self): method = Image.EXTENT data = (0, 0, 100, 100) return method, data :param data: Extra data to the transformation method. :param resample: Optional resampling filter. It can be one of :py:data:`PIL.Image.NEAREST` (use nearest neighbour), :py:data:`PIL.Image.BILINEAR` (linear interpolation in a 2x2 environment), or :py:data:`PIL.Image.BICUBIC` (cubic spline interpolation in a 4x4 environment). If omitted, or if the image has mode "1" or "P", it is set to :py:data:`PIL.Image.NEAREST`. See: :ref:`concept-filters`. :param fill: If ``method`` is an :py:class:`~PIL.Image.ImageTransformHandler` object, this is one of the arguments passed to it. Otherwise, it is unused. :param fillcolor: Optional fill color for the area outside the transform in the output image. :returns: An :py:class:`~PIL.Image.Image` object. r?rErirM)r?rE)rfÚfillræNzmissing method datarBr)r?rE)rr)rKrkrr{rmÚImageTransformHandlerr*rær‰ržr’r�r“ÚMESHÚ_Image__transformerÚQUAD) r€rLr rrfr­r|r)rZquadrrr r{w s(0     zImage.transformc CsD|d|d}|d|d}|tkr8|dd…}�n8|tkrz|\} } } } | | |} | | |}t}| d| d|| f}nö|tkr�|dd…}nà|tk�rh|dd…}|dd…}|dd…}|dd…}|\} } d|}d|}| |d| ||d| ||d|d|d| ||| |d| ||d| ||d|d|d| ||f}ntd ƒ‚|tttfk�r|tt t fk�r²td t d t d i|d |›d�}n d|›d�}dd„tdftdftdffDƒ}t|ddj |dd…ƒd|dƒ‚|j ƒ|j ƒ|j dk�r(t}|jj||j||||ƒdS)Nrrrrr.ér&gð?zunknown transformation methodz Image.BOXz Image.HAMMINGzImage.LANCZOS/Image.ANTIALIASz (z) cannot be used.zUnknown resampling filter (z).cSs g|]}dj|d|dƒ‘qS)z{} ({})rr)r³)rârrrr rùü sz'Image.__transformer..z Image.NEARESTzImage.BILINEARz Image.BICUBICz Use z, z or r=rBrjrj)r=rB)r…ÚEXTENTÚ PERSPECTIVEr±r‰rkrmrlrorprnrØr©rKr)Z transform2)r€rrÜr rrfr­rˆr#rrrrZxsZysrŠÚswÚseÚneZAsZAtrtrurrr Z __transformerÇ s^        "( ( zImage.__transformercCs|jƒ|j|jj|ƒƒS)a¶ Transpose image (flip or rotate in 90 degree steps) :param method: One of :py:data:`PIL.Image.FLIP_LEFT_RIGHT`, :py:data:`PIL.Image.FLIP_TOP_BOTTOM`, :py:data:`PIL.Image.ROTATE_90`, :py:data:`PIL.Image.ROTATE_180`, :py:data:`PIL.Image.ROTATE_270`, :py:data:`PIL.Image.TRANSPOSE` or :py:data:`PIL.Image.TRANSVERSE`. :returns: Returns a flipped or rotated copy of this image. )r©rŸr)r})r€r rrr r} s zImage.transposecCs|jƒ|j|jj|ƒƒS)zj Randomly spread pixels in an image. :param distance: Distance to spread pixels. )r©rŸr)Ú effect_spread)r€Zdistancerrr r¸ szImage.effect_spreadcCs$ddlm}|jstdƒ‚|j|ƒS)z#Returns a QImage copy of this imager)ÚImageQtzQt bindings are not installed)r`r¹Úqt_is_installedrbÚtoqimage)r€r¹rrr r»' s zImage.toqimagecCs$ddlm}|jstdƒ‚|j|ƒS)z$Returns a QPixmap copy of this imager)r¹zQt bindings are not installed)r`r¹rºrbÚ toqpixmap)r€r¹rrr r¼/ s zImage.toqpixmap)NN)N)rÆ)rÜ)rÆ)rñNrNr)N)N)rñ)N)NN)NN)NN©rr©rr)r½r¾)N)r]r^)rC)N)NNN)N)N)NN)Qrr#r$Ú__doc__r³Zformat_descriptionZ!_close_exclusive_fp_after_loadingr�r!Úpropertyr™ršrLrŸr r¥r¤rªr«r¸r¼r¾rÂrÌrÍrÑr»rßrÏr©rðÚWEBrrür�Ú__copy__rr rrrrr r"rær&r8rCrErºrrGr!rKrNrOrVr\r_rÎrÿrbrgrqrrrkr‹r±r�r¡r)r£r¤rlr¬r{r°r}r¸r»r¼rrrr r�üsž          +  0 O C          P . .6  "& F b $ l X  KOI r�c@seZdZdZdS)rUzb Used as a mixin by point transforms (for use with :py:meth:`~PIL.Image.Image.point`) N)rr#r$r¿rrrr rU< srUc@seZdZdZdS)r®zi Used as a mixin by geometry transforms (for use with :py:meth:`~PIL.Image.Image.transform`) N)rr#r$r¿rrrr r®E sr®cCstƒjtjdƒƒS)z+Create greyscale wedge (for debugging only)r>)r�rŸrrZwedgerrrr Ú_wedgeU srÃcCsNt|ttfƒstdƒ‚t|ƒdkr*tdƒ‚|ddksB|ddkrJtdƒ‚dS)zª Common check to enforce type and sanity check on size tuples :param size: Should be a 2 tuple of (width, height) :returns: True, or raises a ValueError zSize must be a tuplerz Size must be a tuple of length 2rrzWidth and height must be >= 0T)rmrrnr‰rX)rLrrr Ú _check_size[ s rÄcCs¤t|ƒ|dkr$tƒjtj||ƒƒSt|tƒrFddlm}|j ||ƒ}tƒ}|dkr�t|t t fƒr�t |ƒdkr�ddlm }|j ƒ|_|jj |ƒ}|jtj|||ƒƒS) a™ Creates a new image with the given mode and size. :param mode: The mode to use for the new image. See: :ref:`concept-modes`. :param size: A 2-tuple, containing (width, height) in pixels. :param color: What color to use for the image. Default is black. If given, this should be a single integer or floating point value for single-band modes, and a tuple for multi-band modes (one value per band). When creating RGB images, you can also use color strings as supported by the ImageColor module. If the color is None, the image is not initialised. :returns: An :py:class:`~PIL.Image.Image` object. Nr)rLrBrr&)rœ)rr&)rÄr�rŸrrržrmrþr`rLrýrrnrXrœr’r­)rKrLZcolorrLr)rœrrr ržm s   "   ržrÆcGsZt|ƒt|ƒdkr*t|dtƒr*|d}|dkr>|fkr>|}t||ƒ}|j|||ƒ|S)aˆ Creates a copy of an image memory from pixel data in a buffer. In its simplest form, this function takes three arguments (mode, size, and unpacked pixel data). You can also use any pixel decoder supported by PIL. For more information on available decoders, see the section :ref:`Writing Your Own File Decoder `. Note that this function decodes pixel data only, not entire images. If you have an entire image in a string, wrap it in a :py:class:`~io.BytesIO` object, and use :py:func:`~PIL.Image.open` to load it. :param mode: The image mode. See: :ref:`concept-modes`. :param size: The image size. :param data: A byte buffer containing raw data for the given mode. :param decoder_name: What decoder to use. :param args: Additional parameters for the given decoder. :returns: An :py:class:`~PIL.Image.Image` object. rrrÆ)rÄrXrmrnržrÏ)rKrLrrtrur)rrr rÏ” s rÏcGsŒt|ƒt|ƒdkr*t|dtƒr*|d}|dkr||fkrD|ddf}|dtkr|t|dƒ}|jtj|||d|ƒƒ}d|_ |St |||||ƒS)að Creates an image memory referencing pixel data in a byte buffer. This function is similar to :py:func:`~PIL.Image.frombytes`, but uses data in the byte buffer, where possible. This means that changes to the original buffer object are reflected in this image). Not all modes can share memory; supported modes include "L", "RGBX", "RGBA", and "CMYK". Note that this function decodes pixel data only, not entire images. If you have an entire image file in a string, wrap it in a :py:class:`~io.BytesIO` object, and use :py:func:`~PIL.Image.open` to load it. In the current version, the default parameters used for the "raw" decoder differs from that used for :py:func:`~PIL.Image.frombytes`. This is a bug, and will probably be fixed in a future release. The current release issues a warning if you do this; to disable the warning, you should provide the full set of parameters. See below for details. :param mode: The image mode. See: :ref:`concept-modes`. :param size: The image size. :param data: A bytes or other buffer object containing raw data for the given mode. :param decoder_name: What decoder to use. :param args: Additional parameters for the given decoder. For the default encoder ("raw"), it's recommended that you provide the full set of parameters:: frombuffer(mode, size, data, "raw", mode, 0, 1) :returns: An :py:class:`~PIL.Image.Image` object. .. versionadded:: 1.1.4 rrrÆ)rr) rÄrXrmrnÚ _MAPMODESržrŸrrZ map_bufferr•rÏ)rKrLrrtrur)rrr Ú frombufferº s#   rÆc $CsV|j}|d}t|ƒ}|jddƒ}|dkr¸yd|dd…|df}Wn,tk rr}ztdƒ|‚WYdd}~XnXyt|\}}Wq¼tk r´}ztd|ƒ|‚WYdd}~Xq¼Xn|}|dkrÊd} n|dkrØd} nd} || k�rütd|›d| ›d�ƒ‚|dk�r dn|d|df} |dk �rBt|dƒ�r:|jƒ}n|j ƒ}t || |d|ddƒS)a¬ Creates an image memory from an object exporting the array interface (using the buffer protocol). If ``obj`` is not contiguous, then the ``tobytes`` method is called and :py:func:`~PIL.Image.frombuffer` is used. If you have an image in NumPy:: from PIL import Image import numpy as np im = Image.open('hopper.jpg') a = np.asarray(im) Then this can be used to convert it to a Pillow image:: im = Image.fromarray(a) :param obj: Object with array interface :param mode: Mode to use (will be determined from type if None) See: :ref:`concept-modes`. :returns: An image object. .. versionadded:: 1.1.6 rÃÚstridesNrrrÄzCannot handle this data typez$Cannot handle this data type: %s, %sr=r>r@rBrArCrr&zToo many dimensions: z > r¬rr»rÆ)rr)r=r>r@rBrA) rÇrXrúrprˆÚ_fromarray_typemapr‰r*r»ÚtostringrÆ) ÚobjrKrïrÃÚndimrÇZtypekeyrkréZndmaxrLrrr Ú fromarrayï s6 "    rÌcCs$ddlm}|jstdƒ‚|j|ƒS)z-Creates an image instance from a QImage imager)r¹zQt bindings are not installed)r`r¹rºrbÚ fromqimage)r)r¹rrr rÍ+ s rÍcCs$ddlm}|jstdƒ‚|j|ƒS)z.Creates an image instance from a QPixmap imager)r¹zQt bindings are not installed)r`r¹rºrbÚ fromqpixmap)r)r¹rrr rÎ4 s rÎú1;8ú|i1úI;8úI;16SúI;16BSúI;32úI;32BúI;32SúI;32BSúf4úF;32BFúf8úF;64BFr?cCshtdkr dS|d|d}|dtkrBtd|›ddt›d�ƒ‚|tkrdtjd|›dt›d�tƒdS)Nrrrz Image size (z pixels) exceeds limit of z0 pixels, could be decompression bomb DOS attack.)ÚMAX_IMAGE_PIXELSr%rrr")rLZpixelsrrr rY s rÚrc sr|dkrtdt|ƒ›�ƒ‚nt|tjƒr0tdƒ‚|dkr>t}nt|ttfƒsTtdƒ‚d‰d}t|t ƒrtt |j ƒƒ}n t |ƒr€|}|r”t j|dƒ}d ‰y|jd ƒWn,ttjfk rÎtj|jƒƒ}d ‰YnX|jd ƒ}tƒg‰‡‡fd d „}|||||ƒ}|dk�r tƒ�r |||||ƒ}|�r0ˆ|_|Sˆ�r>|jƒxˆD]}tj|ƒ�qDWtd|�rf|n|ƒ‚dS)a` Opens and identifies the given image file. This is a lazy operation; this function identifies the file, but the file remains open and the actual image data is not read from the file until you try to process the data (or call the :py:meth:`~PIL.Image.Image.load` method). See :py:func:`~PIL.Image.new`. See :ref:`file-handling`. :param fp: A filename (string), pathlib.Path object or a file object. The file object must implement ``file.read``, ``file.seek``, and ``file.tell`` methods, and be opened in binary mode. :param mode: The mode. If given, this argument must be "r". :param formats: A list or tuple of formats to attempt to load the file in. This can be used to restrict the set of formats checked. Pass ``None`` to try all supported formats. You can print the set of available formats by running ``python3 -m PIL`` or using the :py:func:`PIL.features.pilinfo` function. :returns: An :py:class:`~PIL.Image.Image` object. :exception FileNotFoundError: If the file cannot be found. :exception PIL.UnidentifiedImageError: If the image cannot be opened and identified. :exception ValueError: If the ``mode`` is not "r", or if a ``StringIO`` instance is used for ``fp``. :exception TypeError: If ``formats`` is not ``None``, a list or a tuple. ráz bad mode zKStringIO cannot be used to open an image. Binary data must be used instead.Nzformats must be a list or tupleFr`ÚrbTréc sÊxÄ|D]¼}|jƒ}|tkr tƒy`t|\}}| p:||ƒ}t|ƒttgkrXˆj|ƒn&|r~|jdƒ|||ƒ}t|j ƒ|SWqt t t t jfk r wYqtk rÀˆrº|jƒ‚YqXqWdS)Nr)r•rirlÚtyperþrçrÖr�rrLÚ SyntaxErrorÚ IndexErrorrˆÚstructÚerrorÚ BaseExceptionr¤) r¡r·ÚprefixÚformatsr÷ÚfactoryÚacceptrRr))Úaccept_warningsÚ exclusive_fprr Ú _open_core® s*       zopen.._open_corezcannot identify image file %r)r‰Úreprrmr¿ÚStringIOÚIDrrnrˆrrþÚresolverr—r˜r�rÚUnsupportedOperationrÀÚreadrcrlr¢r¤rrr)r¡rKrër·rêrðr)rtr)rîrïr r˜m sP       r˜cCs&|jƒ|jƒ|jtj|j|jƒƒS)zù Alpha composite im2 over im1. :param im1: The first image. Must have mode RGBA. :param im2: The second image. Must have mode RGBA, and the same size as the first image. :returns: An :py:class:`~PIL.Image.Image` object. )r©rŸrrrOr))Úim1Úim2rrr rOß s rOcCs(|jƒ|jƒ|jtj|j|j|ƒƒS)aŒ Creates a new image by interpolating between two input images, using a constant alpha.:: out = image1 * (1.0 - alpha) + image2 * alpha :param im1: The first image. :param im2: The second image. Must have the same mode and size as the first image. :param alpha: The interpolation alpha factor. If alpha is 0.0, a copy of the first image is returned. If alpha is 1.0, a copy of the second image is returned. There are no restrictions on the alpha value. If necessary, the result is clipped to fit into the allowed output range. :returns: An :py:class:`~PIL.Image.Image` object. )r©rŸrrÚblendr))r÷rør[rrr rùî srùcCs|jƒ}|j|d|ƒ|S)af Create composite image by blending images using a transparency mask. :param image1: The first image. :param image2: The second image. Must have the same mode and size as the first image. :param mask: A mask image. This image can have mode "1", "L", or "RGBA", and must have the same size as the other two images. N)r�rN)Zimage1Zimage2rJrÜrrr Ú composite s rúcGs|j|dƒS)aá Applies the function (which should take one argument) to each pixel in the given image. If the image has more than one band, the same function is applied to each band. Note that the function is evaluated once for each possible pixel value, so you cannot use random components or other generators. :param image: The input image. :param function: A function object, taking one integer argument. :returns: An :py:class:`~PIL.Image.Image` object. r)rV)rÜrurrr Úeval s rûcCsžt|ƒt|ƒksd|kr tdƒ‚xB|dd…D]2}|jt|ƒkrHtdƒ‚|j|djkr.tdƒ‚q.Wx|D] }|jƒqjW|djtj |fdd „|DƒžŽƒS) am Merge a set of single band images into a new multiband image. :param mode: The mode to use for the output image. See: :ref:`concept-modes`. :param bands: A sequence containing one single-band image for each band in the output image. All bands must have the same size. :returns: An :py:class:`~PIL.Image.Image` object. Ú*zwrong number of bandsrNz mode mismatchrz size mismatchcSsg|] }|j‘qSr)r))rârŒrrr rù; szmerge..) rYrXr‰rKrUrLr©rŸrrr)rKrVr%rrr r& s    rcCs"|jƒ}tj|ƒ||ft|<dS)a1 Register an image file plugin. This function should not be used in application code. :param id: An image format identifier. :param factory: An image file factory method. :param accept: An optional function that can be used to quickly reject images having another format. N)r•rórÖri)r½rìrírrr Ú register_openB s  rýcCs|t|jƒ<dS)zÈ Registers an image MIME type. This function should not be used in application code. :param id: An image format identifier. :param mimetype: The image MIME type for this format. N)ÚMIMEr•)r½Zmimetyperrr Ú register_mimeQ srÿcCs|t|jƒ<dS)zÏ Registers an image save function. This function should not be used in application code. :param id: An image format identifier. :param driver: A function to save images in this format. N)rjr•)r½Údriverrrr Ú register_save\ srcCs|t|jƒ<dS)zü Registers an image function to save all the frames of a multiframe format. This function should not be used in application code. :param id: An image format identifier. :param driver: A function to save images in this format. N)r–r•)r½rrrr Úregister_save_allg s rcCs|jƒt|jƒ<dS)zÇ Registers an image extension. This function should not be used in application code. :param id: An image format identifier. :param extension: An extension used for this format. N)r•r”r“)r½Ú extensionrrr Úregister_extensions srcCsx|D]}t||ƒqWdS)zÎ Registers image extensions. This function should not be used in application code. :param id: An image format identifier. :param extensions: A list of extensions used for this format. N)r)r½Ú extensionsrrrr Úregister_extensions~ s rcCsts tƒtS)za Returns a dictionary containing all file extensions belonging to registered plugins )r”rlrrrr Úregistered_extensionsŠ srcCs |t|<dS)a Registers an image decoder. This function should not be used in application code. :param name: The name of the decoder :param decoder: A callable(mode, args) that returns an ImageFile.PyDecoder object .. versionadded:: 4.1.0 N)ro)rrvrrr Úregister_decoder” s rcCs |t|<dS)a Registers an image encoder. This function should not be used in application code. :param name: The name of the encoder :param encoder: A callable(mode, args) that returns an ImageFile.PyEncoder object .. versionadded:: 4.1.0 N)rx)rrzrrr Úregister_encoder¢ s r cKsd|d<t|f|ŽdS)NTÚ_internal_pillow)Ú_showxv)rÜr´rrr r ´ sr cKs<ddlm}d|kr|d=n tjdtƒ|j||f|ŽdS)Nr)Ú ImageShowr z[_showxv is deprecated and will be removed in Pillow 9 (2022-01-02). Use Image.show instead.)r`r rrrr¡)rÜržr´r rrr r ¹ s r cCstƒjtj|||ƒƒS)a Generate a Mandelbrot set covering the given extent. :param size: The requested size in pixels, as a 2-tuple: (width, height). :param extent: The extent to cover, as a 4-tuple: (x0, y0, x1, y2). :param quality: Quality. )r�rŸrrÚeffect_mandelbrot)rLZextentZqualityrrr r Ë s r cCstƒjtj||ƒƒS)z» Generate Gaussian noise centered around 128. :param size: The requested size in pixels, as a 2-tuple: (width, height). :param sigma: Standard deviation of noise. )r�rŸrrÚ effect_noise)rLÚsigmarrr rØ srcCstƒjtj|ƒƒS)zl Generate 256x256 linear gradient from black to white, top to bottom. :param mode: Input mode. )r�rŸrrÚlinear_gradient)rKrrr rã srcCstƒjtj|ƒƒS)zm Generate 256x256 radial gradient from black to white, centre to edge. :param mode: Input mode. )r�rŸrrÚradial_gradient)rKrrr rì srcCs|dkrtj}�xòdtjfdtjfdtjfgD]Ò\}}||kr@q.||jƒ}d}x0d D](\}}|j|ƒrV|}|dt|ƒ …}qVWyt |ƒ|}Wn&t k r¸t j |›d�ƒw.YnXy ||ƒWq.t k �rþ}zt j |›d |›�ƒWYdd}~Xq.Xq.WdS)NZPILLOW_ALIGNMENTZPILLOW_BLOCK_SIZEZPILLOW_BLOCKS_MAXrr,érôz is not intz: ©r,ré©rôr)rr) r¯ÚenvironrrZ set_alignmentZset_block_sizeZset_blocks_maxr“r°rXrêr‰rr)ÚenvÚvar_nameÚsetterÚvarÚunitsZpostfixÚmulrkrrr Ú_apply_env_variablesù s.   rc@sœeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z d%dd„Z dd„Z d&dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„ZdS)'r:NcCsi|_i|_d|_d|_dS)N)Ú_dataÚ_ifdsÚ_infoÚ _loaded_exif)r€rrr r� sz Exif.__init__c Cs<y"t|ƒdkr t|tƒr |dSWntk r6YnX|S)Nrr)rXrmrnr§)r€r}rrr Ú_fixup& s  z Exif._fixupcs‡fdd„|jƒDƒS)Ncsi|]\}}ˆj|ƒ|“qSr)r")râr,rõ)r€rr r-1 sz$Exif._fixup_dict..)r/)r€Zsrc_dictr)r€r Ú _fixup_dict. szExif._fixup_dictc Cs\y|jj|ƒWnttfk r(Yn0Xddlm}|j|jƒ}|j|jƒ|j |ƒSdS)Nr)ÚTiffImagePlugin) r¡r�rprˆr`r$ÚImageFileDirectory_v2Úheadr©r#)r€rYr$r“rrr Ú _get_ifd_dict3 s   zExif._get_ifd_dictcCs|jdkrdSdSdS)Nr1sII*sMM*)r=)r€rrr Ú _get_headA s zExif._get_headcCs¬||jkrdS||_|jjƒ|jjƒ|s6d|_dS|jdƒrL|dd…}tj|ƒ|_|jj dƒ|_ ddl m }|j |j ƒ|_|jj|_|jj|jjƒ|jj|jƒdS)NsExifr.r²r)r$)r!rÚclearrr Ú startswithr¿rÀr¡rör&r`r$r%r<r=r�Únextr©)r€rr$rrr r©G s"        z Exif.loadcCsžd|_|jjƒ|jjƒddlm}||_|dk r@|jƒ|_n|jj dƒ|_|j |jƒ|_ |j dkrp|j j |_ |dkr€|j j}|jj|ƒ|j j|jƒdS)Nr)r$r²)r!rr)rr`r$r¡r(r&rör%r r=r<r+r�r©)r€r¡rYr$rrr r>c s       zExif.load_from_fpcCsJt|ƒ}d|kr,|j|dƒ}|r,|j|ƒd|krF|j|dƒ|d<|S)Nii‡i%ˆ)Údictr'Úupdate)r€Z merged_dictÚifdrrr Ú_get_merged_dictx s zExif._get_merged_dictr²cCs¤ddlm}|jƒ}|j|d�}xp|jƒD]d\}}|d kr†t|tƒ r†|j|ƒ}|dkr†d|kr†t|dtƒ r†|jƒ}|jdƒ|d<|||<q*Wd||j |ƒS) Nr)r$)Zifhéi‡é%‚é%ˆi sExif)r0r1r2) r`r$r(r%r/rmr,Úget_ifdr�r»)r€rYr$r&r.r*r}rrr r»‡ s    z Exif.tobytescCsD||jk�r6|dkr4||kr0|j||ƒ|j|<�n|d k�r6d|jkrR|jdƒ|jd|}|dk�r&ddlm}|dd…dk�rÐt|dƒ}||d…}i}�xtd tjd |dd …ƒd ƒD]ð}tjd ||d d |dd d …ƒ\}} } } y|j | \} } Wnt k �r"wÄYnX| | }|dk�r^tjd| ƒ\}||d ||d …} n | d|…} t | ƒ|k�ršt j d|›dt | ƒ›d|›�ƒqÄ| �s¢qÄ| |ƒ| dƒ||<qÄWt|j|ƒƒ|j|<�q6|jdƒdk�r6i}�x2td tjd|dd …ƒd ƒD�]}tjd||d d |dd d …ƒ\}} } } |dk�rtjd| ƒ\}|jj|ƒd|jjdƒi}|jjdƒt|jjd ƒƒ|d<|jjdƒ|jjdƒ|d<|jjd ƒ|jjdƒ}|j tjd} | |ƒ|dƒ|d<|jjdƒ|jjd ƒ|d<dt|j|ƒƒi}�qW||j|<n|j|ƒ|j|<|jj|iƒS)!Néi‡é%ˆé é|’r)r%r²sFUJIFILMrzHz>HHL4siz>LZModelIDZ TimeStampZInternalSerialNumberZParallaxZCategory)r4r5)r6r7)rr'r3r$r%r rûrçÚunpackZ_load_dispatchrprXrrr,r#rúr¡r�rörÚFLOAT)r€r*Ztag_datar%Z ifd_offsetZifd_dataZ makernoter÷Zifd_tagrMÚcountrZ unit_sizeÚhandlerrLrYZ camerainfoZparallaxrrr r3™ sz        &,  (,        z Exif.get_ifdcCs0|jdk r&x|jjƒD] }||qWt|jƒS)N)r Úkeysrþr)r€r*rrr Ú__str__õ s  z Exif.__str__cCs(t|jƒ}|jdk r |j|jƒt|ƒS)N)Úsetrr r-rX)r€r=rrr Ú__len__ý s   z Exif.__len__cCsF|jdk r<||jkr<||jkr<|j|j|ƒ|j|<|j|=|j|S)N)r rr")r€r*rrr Ú __getitem__szExif.__getitem__cCs||jkp|jdk o||jkS)N)rr )r€r*rrr Ú __contains__ szExif.__contains__cCs*|jdk r||jkr|j|=||j|<dS)N)r r)r€r*r}rrr Ú __setitem__ szExif.__setitem__cCs*|jdk r||jkr|j|=n|j|=dS)N)r r)r€r*rrr Ú __delitem__s zExif.__delitem__cCs(t|jƒ}|jdk r |j|jƒt|ƒS)N)r?rr r-Úiter)r€r=rrr Ú__iter__s   z Exif.__iter__)N)r²)rr#r$r=r�r"r#r'r(r©r>r/r»r3r>r@rArBrCrDrFrrrr r: s$  \r:)rrii@iiUUU)r3N)r4N)r4r)r4N)r4r)r4r&)r4r&)r4r&)r4r)r4r)r4r)r5N)r6N)r5N)r7N)r8N)r7N)r9N)r:N)r9N)r;N)r<N)r;N)r>rBrDrErFrPrQrR)r)rÆ)rÆ)N©rr)rGr3)r=rÏ©rr)rHr4)r>r>©rr)rIrÐ)r@rÑ©rr)rJr5)r@rP©rr)rKr6)r@rR©rr)rLr7)r@rÒ©rr)rMr8)r@rÓ©rr)rNr9)r@rÔ©rr)rOr:)r@rÕ©rr)rPr;)r@rÖ©rr)rQr<)r@rשrr)rRrØ)rArÙ©rr)rSrÚ)rArÛ©rr)rTrÜ)rArÝ©rr)rUrÞ)rArß©rrr)rVr4)r?r?©rrr)rWr4)rCrC©rrr&)rXr4)rErE)r@r@)rr)rArA)rr)ráN)N)N)N) Úatexitr—r¿Úloggingrdr†r¯r@rçr�r­rÚcollections.abcrrZpathlibrZdefusedxml.ElementTreer4rbr`rrrr r r Z_binaryr Z_utilr rÚ version_infor!rrarrrÚ getLoggerrrdÚRuntimeWarningr"r§r%rêràr'rrrqrõrþr*rr*rîrír,ÚNONEZFLIP_LEFT_RIGHTZFLIP_TOP_BOTTOMrr~r€Z TRANSPOSEZ TRANSVERSEr…r³r´r±r¯rkrormZLINEARrprlZCUBICrnZ ANTIALIASrcZORDEREDZ RASTERIZErrÁrr Z MAXCOVERAGEr r r/ZFILTEREDZ HUFFMAN_ONLYZRLEZFIXEDrórirþrjr–r”rorxÚ byteorderZ_ENDIANrJrOZMODESrÅrTrUrWrYr_rcrlrwr{r~r|r�r�rUr®rÃrÄržrÏrÆrÌrÍrÎrÈrr˜rOrùrúrûrrýrÿrrrrrrr r r r rrrrÚregisterÚ clear_cacher:rrrr Ús¦                    .   P  ' & 5 <    r