K iuB r UddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlmZddlmZmZmZddlmZmZmZmZmZmZddlmZmZm Z dd l!m"Z"dd l#m$Z$m%Z%d e&d < dd l'm(Z(dZ*e*rddlm+Z+m,Z,m-Z-ddl.m/Z/ddlm0Z0m1Z1ejde3Z4Gdde5Z6Gdde7Z8dZ9de&d<e:dZ;de&d< ddlme=ddk7rde>e=dddeZ?e)e? Gd"d#eZDGd$d%eZEGd&d'eZFeFjd(eFjd)eFjd)eFjd*eFjd+iZLGd,d-eZMGd.d/eZNGd0d1eZOe je3ZQeDeEeFeMeNeOfD]'ZeD] ZReSeQeRjeRj")eVe=d2r<iZnd=e&d?<iZod;e&d@<iZpdAe&dB<iZqdCe&dD<e jdEk(rdFndGZsddIZtgdJZudKZvddLZwddMZxddNZyddOZzda{ddPZ|ddQZ} d ddRZ~ d ddSZGdTdUZ ddVZGdWdXeZGdYdHZGdZd[ejZGd\d]ejZdd^Z d dd_Z d dd`Z d ddaZGdbdceZGdddeeZdddfZ ddgZddhZddiZidjdkdlgfdmdndndogfdpdqdrgfdsdqdtgfdudqdvgfdwdqdxgfdydqdzgfd{dqd|gfd}dqd~gfddqdgfddqdgfdddgfdddgfdddgfdddgfdddddgfdddgdfdddgdfdesdfdqdqgfdesdfddgfiZddZ d ddZddZddZddZddZddZ d ddZddZ ddZ ddZddZddZddZddZddZddZ ddZddZddZddZdddZeejPe=jRe*ree:e0fZneZGddeZy#e)$rdZ(YJwxYw#e)$raZ@eAe@jdre jd e5eAe@jd!re jeAe@e5dZ@[@wwxYw)) annotationsN)MutableMapping)IntEnum)IOProtocolcast)ExifTags ImageModeTiffTagsUnidentifiedImageError __version___plugins)i32leo32beo32le) deprecate) DeferredErroris_pathzModuleType | None ElementTree)rF)CallableIteratorSequence) ModuleType)AnyLiteralc eZdZy)DecompressionBombWarningN__name__ __module__ __qualname__O/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/PIL/Image.pyrrKr$rc eZdZy)DecompressionBombErrorNrr#r$r%r(r(Or&r$r(boolWARN_POSSIBLE_FORMATSiUUU int | NoneMAX_IMAGE_PIXELS)_imagingPILLOW_VERSIONzUThe _imaging extension was built for another version of Pillow or PIL: Core version: z Pillow version: zModule use of pythonz?The _imaging extension was built for another version of Python.zThe _imaging extensionc(eZdZdZdZdZdZdZdZdZ y) Transposerr N) r r!r"FLIP_LEFT_RIGHTFLIP_TOP_BOTTOM ROTATE_90 ROTATE_180 ROTATE_270 TRANSPOSE TRANSVERSEr#r$r%r0r0s%OOIJJIJr$r0c eZdZdZdZdZdZdZy) Transformrr r1r2r3N)r r!r"AFFINEEXTENT PERSPECTIVEQUADMESHr#r$r%r>r>s F FK D Dr$r>c$eZdZdZdZdZdZdZdZy) Resamplingrr3r1r4r2r N) r r!r"NEARESTBOXBILINEARHAMMINGBICUBICLANCZOSr#r$r%rErEs G CHGGGr$rE??@g@ceZdZdZdZdZdZy)Ditherrr r1r2N)r r!r"NONEORDERED RASTERIZEFLOYDSTEINBERGr#r$r%rPrPs DGINr$rPceZdZdZdZy)Paletterr N)r r!r"WEBADAPTIVEr#r$r%rVrVs CHr$rVceZdZdZdZdZdZy)Quantizerr r1r2N)r r!r" MEDIANCUT MAXCOVERAGE FASTOCTREE LIBIMAGEQUANTr#r$r%rZrZsIKJMr$rZDEFAULT_STRATEGY)Element) PrettyPrinter) ImageFile ImageFilter ImagePaletteImageQtTiffImagePlugin) CapsuleType NumpyArrayStrOrBytesPath list[str]IDzodict[str, tuple[Callable[[IO[bytes], str | bytes], ImageFile.ImageFile], Callable[[bytes], bool | str] | None]]OPENdict[str, str]MIMEz:dict[str, Callable[[Image, IO[bytes], str | bytes], None]]SAVESAVE_ALL EXTENSIONz$dict[str, type[ImageFile.PyDecoder]]DECODERSz$dict[str, type[ImageFile.PyEncoder]]ENCODERSlittle<>Imagectj|j}|j|jf}t |j }|dk7r||fz }||jfSNr )r getmodemodeheightwidthlenbandstypestr)immshapeextras r%_conv_type_shapersW"''"A ii2E LE z % !)) r$)1CMYKFHSVII;16I;16BI;16LzI;16NLLALaLABPPARGBRGBARGBaRGBXYCbCr)rrrrrrrrc@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 rzbasemoder{s r% getmodebasers   T " + ++r$c@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. )r rzbasetypers r% getmodetypers   T " + ++r$c@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. )r rzrrs r%getmodebandnamesr's   T " ( ((r$cRttj|jS)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. )r~r rzrrs r% getmodebandsr6s  y  &,, --r$c.tdk\ry ddlm}|sJ ddlm}|sJ ddlm}|sJ ddlm}|sJ ddlm}|sJ day#t$rY>wxYw#t$rYAwxYw#t$rYDwxYw#t$rYGwxYw#t$rYdaywxYw)z| Explicitly loads BMP, GIF, JPEG, PPM and PPM file format drivers. It is called when opening or saving images. r N)BmpImagePlugin)GifImagePlugin)JpegImagePlugin)PpmImagePlugin)PngImagePlugin) _initializedr ImportErrorrrrr)rrrrrs r%preinitrGsq $~ $~ % $~ $~L7               L sU A A A( A7 B AA A%$A%( A43A47 BB BBcJtdk\rytjdd}tD]<} tj d|t |d|ttg>tstrdayy#t$r!}tj d||Yd}~td}~wwxYw) z Explicitly initializes the Python Imaging Library. This function loads all available file format drivers. It is called when opening or saving images if :py:meth:`~preinit()` is insufficient, and by :py:meth:`~PIL.features.pilinfo`. r1F.rz Importing %szImage: failed to import %s: %sNT) rr rpartitionrloggerdebug __import__globalslocalsrrlro) parent_nameplugines r%initrtsq%%c*1-KF F LL 0 +ax0')VXr JF t    F LL961 E E Fs9A88 B"BB"c|d}nt|ts|f} t|}||g||zS#t$rYnwxYw t t |d}n##t $r}d|d}t||d}~wwxYw||g||zS)Nr#_decoderzdecoder  not available) isinstancetuplerrKeyErrorgetattrcoreAttributeErrorOSError)r{ decoder_nameargsrdecoderrmsgs r% _getdecoderr | e $w,<(t+dUl++    "$<. 9: "n5cl!" 4 '$, ''# / ;;A A3A..A3c|d}nt|ts|f} t|}||g||zS#t$rYnwxYw t t |d}n##t $r}d|d}t||d}~wwxYw||g||zS)Nr#_encoderzencoder r)rrrsrrrrr)r{ encoder_namerrencoderrrs r% _getencoderrrrcPeZdZdZd dZd dZd dZeZd dZd dZ d dZ e Z d dZ y ) ImagePointTransformz Used with :py:meth:`~PIL.Image.Image.point` for single band images with more than 8 bits, this represents an affine transformation, where the value is multiplied by ``scale`` and ``offset`` is added. c ||_||_yN)scaleoffset)selfrrs r%__init__zImagePointTransform.__init__s  r$cFt|j |j Sr)rrrrs r%__neg__zImagePointTransform.__neg__s"DJJ; ==r$ct|tr:t|j|jz|j|jzSt|j|j|zSr)rrrrrothers r%__add__zImagePointTransform.__add__sU e0 1& U[[($++ *D #4::t{{U/BCCr$c|| zSrr#rs r%__sub__zImagePointTransform.__sub__suf}r$c|| zSrr#rs r%__rsub__zImagePointTransform.__rsub__su}r$czt|trtSt|j|z|j|zSrrrNotImplementedrrrs r%__mul__zImagePointTransform.__mul__2 e0 1! !"4::#5t{{U7JKKr$czt|trtSt|j|z |j|z Srrrs r% __truediv__zImagePointTransform.__truediv__rr$N)rfloatrrreturnNone)rr)rzImagePointTransform | floatrr) r r!r"__doc__rrr__radd__rrr__rmul__rr#r$r%rrs; >DHL HLr$rc~|tdd}t|tr|j|jfSd|fSNr r)rrrr)expras r%_getscaleoffsetrs< A &'A",Q0C"DAGGQXX P1a&Pr$ceZdZ ddZy)SupportsGetDatacyrr#rs r%getdatazSupportsGetData.getdatas*-r$N)rztuple[Transform, Sequence[int]])r r!r"rr#r$r%rrs. (.r$rceZdZUdZdZded<dZded<dZd_dZe d`dZ e jdad Z e dbd Z e dbd Z e dcd Ze ddd Ze dbdZejdedZdfdZdZdZd_dZd_dZd_dZ dg dhdZdidZdddZdjdZdkdZdldZdldZe dmdZdndZ do dpdZ dqd Z!drd!Z"dsdtd"Z#dudvd#Z$ ds dwd$Z%dxd%Z&d_d&Z'ddde(jRd'f dyd(Z*d'dd)de+jXf dzd*Z-d{d+Z.e.Z/dod|d,Z0 d}d-Z1 d~d.Z2dd/Z3dd0Z4dd1dd2Z5 d dd3Z6dodd4Z7dd5Z8dd6Z9dd7Z:d_d8Z;dd9Ze dd<Z?d_d=Z@ dd>ZAdd?ZB dg dd@ZC dg ddAZD dg ddBZE d ddCZF do ddDZGddEZH d ddFZI d ddGZJ ddHZK do ddIZL ddJZM d ddKZN do ddLZOePjdMdddf ddNZR do ddOZSddPZTddQZUdoddRZVddSZWddTZXdbdUZYePjdVf ddWZ[dePjdXdf ddYZ\ePjdf ddZZ]dd[Z^dd\Z_dd]Z`dd^Zay)rwaD 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` N str | Noneformatformat_descriptionTcfd|_d|_d|_d|_i|_d|_d|_y)Nrrrr)_im_mode_sizepaletteinforeadonly_exifrs r%rzImage.__init__s3<@  9= 68  "& r$ct|jtr|jj|jJ|jSr)rrrexrs r%rzImage.ims7 dhh .((++ xx###xxr$c||_yr)rrrs r%rzImage.im%s r$c |jdSNrsizers r%r}z Image.width)yy|r$c |jdSryr rs r%r|z Image.height-rr$c|jSr)rrs r%r z Image.size1 zzr$c|jSr)rrs r%r{z Image.mode5rr$cf|jxr|jjxs |jSr)rr _readonlyrs r%rzImage.readonly9s$.TXX..A4>>Ar$c||_yr)r)rrs r%rzImage.readonly=s !r$cVt}||_|j|_|j|_|jdvrH|j r |j j|_nddlm }|j|_|jj|_ |S)Nrrr rd) rwrr{rr rrcopyrrdr)rrnewrds r%_newz Image._newAsygGG GG 77k !||"ll//1 *7l779 99>># r$c|Srr#rs r% __enter__zImage.__enter__Qs r$cddlm}t||jr%t|ddr|j d|_yy)Nr rb _exclusive_fpF)rrbrr _close_fpfp)rrrbs r%__exit__zImage.__exit__Ts7 dI// 0t_e4 DG 1r$ct|ddrDtjdk(r*ttdr|jj d|_t td|_y)av 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. mapNwin32pypy_version_infozOperation on closed image) rsysplatformhasattrr%closer ValueErrorrrs r%r+z Image.close\sO 4 %||w&738K+L )-DH !,G!HIr$cp|j|jj|_d|_yr )loadrrrrs r%_copyz Image._copyps# '',,. r$c^|jr|jy|jyr)rr/r.rs r%_ensure_mutablezImage._ensure_mutableus == JJL IIKr$c 8d}|rd|}|s.tj|\}}tj|n|}|j |s||z}|j |r|dk(r|j j||S|j||fi||S)NrrPPM) tempfilemkstemposr+endswithr.rsave_ppmsave)rfileroptionssuffixffilenames r%_dumpz Image._dump{s \F"**62KAx HHQKH$$V,#f, 5 GG  X & DIIh 2' 2r$c|j|juryt|tsJ|j|jk(xrz|j|jk(xr_|j |j k(xrD|j |j k(xr!|j|jk(SNF) __class__rrwr{r r getpalettetobytesrs r%__eq__z Image.__eq__s >> 0%''' II # 2 UZZ' 2 UZZ' 2!U%5%5%77 2 %--/1  r$cd|jjd|jjd|jd|jdd|jddt |d d S) Nrur image mode= size=rxr z at 0xXrv)rBr!r r{r idrs r%__repr__zImage.__repr__sm))*!DNN,C,C+DE))F499Q<.$))A,HtHQ 477i(($))A,*:;,-HHW,= )NGT MM$   Q;"7);7Cs# #xxr$cZ|j|jdk7r d}t||jd}dj d|d|j ddj d d|d |j d dj d d |d j d |dgS)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" rz not a bitmapxbmr$z#define z_width r asciiz_height r z static char z _bits[] = { s};)r.r{r,rDr~r r{)rnamerrfs r%tobitmapzImage.tobitmap*s 99  CS/ !||E"xx4& ! ~R8??H4&1b9@@ItfN3::7C    r$c|jdk(s|jdk(ry|}t|dk(rt|dtr|d}|dk(r|dk(r |j }t |j ||}|j|j|j|}|ddk\r d}t||ddk7r d}t|y)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. rNr rer#znot enough image datazcannot decode image data) r}r|r~rrr{rrxrdecoder,)rrfrr decoder_argsdsrs r%rtzImage.frombytesDs ::?dkkQ.  |  !ja%&H'?L 5 \R%799L  < > 477 HHTN Q419)CS/ ! Q419,CS/ ! r$ct|jz|jrm|jjrV|jj\}}|jj |jj ||d|j_d|j_d|jvr|dvrt|jdtr*|jj|jddn(|jj|jdd|j_nS|jj|jj |jj |j_|j%|jj|jSy)at 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: :py:class:`.PixelAccess` Nr transparencyrrr)rrdirtyrrrsr{rawmoderrintputpalettealphaputpalettealphasrC pixel_accessr)rr{arrs r%r.z Image.loadis4 88 DLLT\\5G5G ,,.ID# GG  t||00$ j@k(r|j j|}|j|} ddl!m"}|jDd| j jGd| _|r | jd=|C | jj/tItt:df|| | jd<| S| Sd|j|fvr|}|dk(r,|jd vr|j5d}|j}n|}|d vrtdd!l!m&}|jOd"}|jOd}|jdk(r||gn||g}|jQ|d|d|j|}|jS|S|tTjV} |j j5||}|j|} |d#vr@|t>j@k7r-ddl!m"}|jDd|jGd| _|r | jd=|m| jdk(rO| jrC | jj/tItt:df|| | jd<| S|| jd<| S#t $r(}t1|dk(rd }n t ||Yd }~d }~wwxYw#tJ$r&| jd=t'j(dY| SwxYw#t $rw tY|j}||jk(r|j j5|}|j5||}n#tZ$r}d}t ||d }~wwxYwYwxYw#t $r;}| jd=t1|dk7rt'j(dYd }~| Sd }~wwxYw)%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. This supports all possible conversions between "L", "RGB" and "CMYK". The ``matrix`` argument only supports "L" and "RGB". When translating a color image to grayscale (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 grayscale ("L") or "RGB" image into a bilevel (mode "1") image uses Floyd-Steinberg dither to approximate the original image luminosity levels. If dither is ``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. When converting from "PA", if an "RGBA" palette is present, the alpha channel from the image will be used instead of the values from the palette. :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:`Dither.NONE` or :data:`Dither.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:`Palette.WEB` or :data:`Palette.ADAPTIVE`. :param colors: Number of colors to use for the :data:`Palette.ADAPTIVE` palette. Defaults to 256. :rtype: :py:class:`~PIL.Image.Image` :returns: An :py:class:`~PIL.Image.Image` object. rrrr)rrzillegal conversionr2c |d|dz|d|dzz|d|dzz|ddzz}tdtdt|S)Nrr r1r2rL)ryminr)rvvalues r%convert_transparencyz+Image.convert..convert_transparencys\aD1Q4K!A$1+5!qt CadSjPEq#c3u:"677r$rc3HK|]}|dz|dzdzyw)r3Nr#).0irmatrixrs r% z Image.convert..s3)-VAEAEAI-F U)s"rNF)rrrrrr)rrrr)rrrzVPalette images with Transparency expressed in bytes should be converted to RGBA imagesTr r z2Couldn't allocate a palette color for transparencyz$cannot allocate more than 256 colorsrrrrrz.Transparency for P mode should be bytes or intr r.z0Couldn't allocate palette entry for transparencyr)rrr)ImageCmssRGBr)rztuple[float, ...]rztuple[int, int, int]rr).r.rr{rrr,rconvert_matrixrrr~rrangequantizesplitmergeconvert_transparentrbyteswarningswarnrrsgetcolorstrputpixelconvertgetpixelrrrrVrXrrdrCrrUr createProfilebuildTransformapplyrPrTrr) rr{rditherrcolorshas_transparencyrrnew_imrgrYrrgbrOtrns delete_trnsttrns_imerrrrd other_modersrgblabprofiles transformmodebaserrs ` @@r%rz Image.convertsEh )TYY6 S(||||((u}!1 )&99;  <'* o%''f5BYYr]FDGGMMQ$6%{{>: 8(8-A88 3;#7 #MLY!^#()!&s<'8!9)$L/; N+M 99 s{}}V,,!ZZ\ 1aEAq!9-LL(TAq6**  449O U"t/K'KGG//dii6OPKK/ //D>#>A$+OO$<$**F -v.B2 ; 7g.>.>#> &6\66ubmmE>RSFN  N+  {{c!fnn 28..2I2IU38_d3V3FKK/ /3 N+ m$.A#&q6-S#S)-A*4S/q$@%& Ad!V N3MM"TUM V@ - -&tyy1tyy(WW__X.ZZf- -* o1, - -4" N31v!GG! N  s{>ZAZ:[,3A]/ Z7Z22Z7:+[)([), ],6A] ], ]%]  ]%%],+],/ ^380^..^3rc|j|/tj}|jdk(rtj}|jdk(r/|tjtj fvr d}t ||r|j|jdk7r d}t ||jdvr d}t ||jjd||j}|j|}|jJ|jj|_ |S|dkr d }t ||j|jj|||}d d l m} |jj} |jj!| | d|t#| z} | j| | |_ |S) a3 Convert the image to 'P' mode with the specified number of colors. :param colors: The desired number of colors, <= 256 :param method: :data:`Quantize.MEDIANCUT` (median cut), :data:`Quantize.MAXCOVERAGE` (maximum coverage), :data:`Quantize.FASTOCTREE` (fast octree), :data:`Quantize.LIBIMAGEQUANT` (libimagequant; check support using :py:func:`PIL.features.check_feature` with ``feature="libimagequant"``). By default, :data:`Quantize.MEDIANCUT` will be used. The exception to this is RGBA images. :data:`Quantize.MEDIANCUT` and :data:`Quantize.MAXCOVERAGE` do not support RGBA images, so :data:`Quantize.FASTOCTREE` is used by default instead. :param kmeans: Integer greater than or equal to zero. :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:`Dither.NONE` or :data:`Dither.FLOYDSTEINBERG` (default). :returns: A new image NrzoFast Octree (method == 2) and libimagequant (method == 3) are the only valid methods for quantizing RGBA imagesrzbad mode for palette image>rrz7only RGB or L mode images can be quantized to a paletterzkmeans must not be negativer r)r.rZr[r{r]r^r,rrrrrrrrdgetpalettemoderCr~) rrmethodkmeansrrrrrrdr{ palette_datas r%rzImage.quantizesF >''FyyF"!,, 99 6     " "2 $ H S/ !  LLN||s"2 o%yy ,O o%fgjj9BYYr]F??. ..$__113FNM A:/CS/ ! YYtww''? @"uu##%uu''d34Hfs4y6HI .\..t\B  r$ct|j|j|jjS)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.rrrrs r%rz Image.copys& yy((r$c||jS|d|dkr d}t||d|dkr d}t||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. r1rz&Coordinate 'right' is less than 'left'r2r z'Coordinate 'lower' is less than 'upper')rr,r.r_cropr)rboxrs r%cropz Image.cropsx ;99;  q6CF?:CS/ ! Vc!f_;CS/ ! yyDGGS122r$ctttt|\}}}}t||z t||z f}t ||j ||||fS)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%rroundabs_decompression_bomb_checkr)rrrx0y0x1y1absolute_valuess r%rz Image._cropsXS#eS/2BBrBw<R"W6!/2wwBB'((r$cy)aY 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 grayscale 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 in pixels, as a 2-tuple: (width, height). Nr#)rr{r s r%draftz Image.draft(s. r$c 6ddlm}|jt|r|}t |ds d}t |t ||j}|jjdk(s|r*|j|j|jSt|jjDcgc];}|j|j|jj|=}}t|j|Scc}w)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 )rcfilterz>filter argument should be ImageFilter.Filter instance or class)rrcr.callabler* TypeErrorrMultibandFilterrrrrrgetbandrr{)rrrcr multibandcimss r%rz Image.filterAs " F XFvx(RCC. v{'B'BC 77==A 99V]]47734 4CH BV =>DIIfmmDGGOOA$67 8  TYY$$ s>ADcTtj|jjS)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 )r rzr{rrs r%getbandszImage.getbands\s  +111r$) alpha_onlycX|j|jj|S)aG Calculates the bounding box of the non-zero regions in the image. :param alpha_only: Optional flag, defaulting to ``True``. If ``True`` and the image has an alpha channel, trim transparent pixels. Otherwise, trim pixels when all channels are zero. Keyword-only argument. :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.rgetbbox)rrs r%rz Image.getbboxfs wwz**r$c|j|jdvrN|jj}t dDcgc]}||s |||f}}t ||kDry|S|jj |Scc}w)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. )rrrrN)r.r{r histogramrr~ getcolors)r maxcolorshrouts r%rzImage.getcolorsys 99 '!!#A?DSz+R!QqTQqT1I+RC+R3x)#Jww  ++ ,Ss  B Bct|j||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. )r.rr)rbands r%rz Image.getdatas/$  77??4( (wwr$cjjjdkDr1tfdt jjDSjj S)a" Gets 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 c3pK|]-}jj|j/ywr)rr getextrema)rrrs r%rz#Image.getextrema..s'WQ+668Ws36)r.rrrrrrs`r%rzImage.getextremasO 77==1 W% BVWW Www!!##r$c dddfd ttjdiSd|jvriStj|jdj d}|j |iS)z Returns a dictionary containing the XMP tags. Requires defusedxml to be installed. :returns: XMP tags in a dictionary. c0tjdd|S)Nz^{[^}]+}r)resub)tags r%get_namezImage.getxmp..get_names66*b#. .r$c|jjDcic]\}}||}}}t|}|r]|D]V}|j} |}||vr1t ||ts ||g||<||j |R|||<X|S|r|j r|j |d<|S|j Scc}}w)NrN)attribitemslistrrr|rN) elementkrrchildrenchildr child_valuer get_values r%r zImage.getxmp..get_values@G@T@T@V$W1Xa[!^$WE$WG}H%2E#EII.D"+E"2Ku})%+t<+0;-E$Kd **;7&1d 2L <<$+LLE&ML||#!%XsC z5XMP data cannot be read without defusedxml dependencyxmps )rrrr)rr`rzstr | dict[str, Any] | None)rrrr fromstringrstripr)rrootrr s @@r%getxmpz Image.getxmpst / (   MMQ RI  !I%%dii&6&=&=h&GH"IdO44r$cR|jt|_n"|jjr |jSd|j_|jj d}|d|jvrDt j dj|jdjddd}nt|dr|jj|j_ |jj|j_|jj|j |jj"||jj%|t&j(j*|jvr|jj d }d }|s|jj d x}rd }|rKt-j.||}|r3t1|d |jt&j(j*<|jS)zj Gets EXIF data from the image. :returns: an :py:class:`~PIL.Image.Exif` object. NTexifzRaw profile type exifrrr2tag_v2zXML:com.adobe.xmpztiff:Orientation(="|>)([0-9])rstiff:Orientation(="|>)([0-9])r1)rExif_loadedrgetrfromhexr~rr*r_bigtiffbigtiff_endianendian load_from_fpr"_offsetr.r Base Orientationrsearchr)r exif_infoxmp_tagspatternmatchs r%getexifz Image.getexifs :: DJ ZZ  :: ! IIMM&)  &$))3!MMGGDII&=>DDTJ12NO x(%)[[%9%9 "$(KK$7$7 ! ''1D1DE  JJOOI & == $ $DJJ 6yy}}%89H#CGTYY]]5-A!A!A; '84 "//&)"""yy0 lE *%l3 +5%*A " +-.GL1$q( )0|00wH   IIn %r$cj|j|jjt|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.rrr)rxys r%rzImage.getpixel_s& wwb **r$c|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)rrIys r%r;zImage.getprojectionns6 ww$$&1AwQr$cD|j|r6|j|jjd|jS|jdvr1|jj||S|j S|jjS)a 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. Counts are grouped into 256 bins for each band, even if the image has more than 8 bits per band. 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 grayscale ("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 grayscale image ("L"). :param mask: An optional mask. :param extrema: An optional tuple of manually-specified extrema. :returns: A list containing pixel counts. rrr)r.rrr{rrmaskextremas r%rzImage.histogramzs.  IIK77$$VTWW5 5 99 "77$$". 48OO4E ww  ""r$cD|j|r6|j|jjd|jS|jdvr1|jj||S|j S|jjS)ah Calculates and returns the entropy for the image. A bilevel image (mode "1") is treated as a grayscale ("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 grayscale 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>)r.rentropyr{rr?s r%rCz Image.entropys$  IIK77??64773 3 99 "77??". 48OO4E ww  r$c`t|tr| d}t||}d}|d}t|dk(r`t|tr |j}n*t|tr |j}n d}t|||d|dz|d|dzfz }t|t r#ddlm}|j||j}nt|trn|j|j|jk7r8|jd k7s|jd vr|j|j}|j}n|}|j|r8|j|jj|||jy|jj||y) 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. See :ref:`colors` for more information. If a mask is given, this method updates only the regions indicated by the mask. You can use either "1", "L", "LA", "RGBA" or "RGBa" images (if present, 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, float 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. Nz=If using second argument as mask, third argument must be Nonerr1z,cannot determine region size; use 4-item boxrr  ImageColorr)rrr)rrwr,r~r rrrFrr{r.rrr1paste)rrrr@rr rFsources r%rGz Image.pastesf\ c5 !U o%DC ;C s8q="e$wwD%(yyE o% CFT!W$c!ftAw&67 7C b#  $((TYY7F E " GGIyyBGG#99%8N)NDII.BUUFF   IIK GGMM&#tww / GGMM&# &r$ct|ttfs d}t|t|ttfs d}t|t |dk(r t|}n4t |dk(rt||j z}n d}t|t |dk(s d}t|t |dkr d}t||d |j zk(r|}n|j|}t||d|jz|d |jzfz}|d |j zk(r|}n|j|}t||} |j| |y ) 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 list or tuplez#Destination must be a list or tupler3r1z*Source must be a sequence of length 2 or 4z*Destination must be a sequence of length 2rzSource must be non-negativerr N) rrrr,r~r rrr}r|alpha_compositerG) rrdestrHroverlay_crop_boxoverlayr backgroundresults r%rJzImage.alpha_compositesK &4-02CS/ !$u .7CS/ ! v;! $V}  [A $V}rww6 >CS/ !4yA~>CS/ ! v;?/CS/ ! v/ /Ggg./GDkT!Ww}}4d1g6NOO &499$ $J3J W5 63r$cV|jt|tr|j|St |r~|j dvr9t |\}}|j|jj||StdDcgc] }|| c}|jjz}n|}|j dk(r d}t||dk7r|Dcgc] }t|}}|j|jj||Scc}wcc}w)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, im: Image) -> Image: # Return result :param mode: Output mode (default is same as input). 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. )rrrrrz+point operation not supported for this mode)r.rImagePointHandlerpointrr{rrrpoint_transformrrr,r)rlutr{rrrflatLutrs r%rRz Image.pointKsB c, -99T? " C=yy..!0 4 vyy!8!8!GHH',Sz2!s1v2TWW]]BGG 99 ?CS/ ! 3;)01AuQx1G1yyw56632s D!"D&c|j|jdvrP t|jdz} |jj ||jj|_|jdvrd}nd}t|trL|jd vr d}t ||j|jd k(r0|jd }n |jj||y|jj!|j|y#t t f$rI}|jj|}|jdvrd}t ||||_Yd}~"d}~wwxYw#t$r}d}t ||d}~wwxYw#t t f$rtd |j|}YwxYw) 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. rr2z alpha channel could not be addedNillegal image moderr r2)rrrr)r1r{rrsetmoderr,rrrrrwr.fillbandrr putband)rr6r{rrrrs r%putalphazImage.putalphas  990 0 -"499-3!GGOOD)"WW\\ 99 $DD eU #zz+* o% JJLzzS  c*   u-  $'G' 3!.Bww&::@(o14 DGG ! -* o1, -*#J/ 3CE2 3sRE>D#E>F#E;2>E60E>6E;;E>> FFF&GGc^|j|jj|||y)a Copies pixel data from a flattened sequence object into the image. The values should start at the upper left corner (0, 0), continue to the end of the line, followed directly by the first value of the second line, and so on. Data will be read 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 flattened sequence object. See :ref:`colors` for more information about values. :param scale: An optional scale value. The default is 1.0. :param offset: An optional offset value. The default is 0.0. N)r1rputdata)rrfrrs r%r]z Image.putdatas$(  eV,r$c ddlm}|jdvr d}t|t ||jrY|j (|j |j |j}nS|j|j}d|_n.t |ts t|}|j ||}d|jvrdnd |_ ||_d|vrd nd |j_|jy) a} 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" or "RGBA" (e.g. "R", "BGR;15", "RGBA;L"). r rrrrWNrr2rrrr) rrdr{r,rrrerrrrr.)rrfrrdrrs r%rszImage.putpalettes. # 992 2&CS/ ! dL55 6||'*,**4<<F3,33DLLI ! dE*T{&l&&w5G DII-T3  &)WnF%  r$c|j|jdvrt|ttfr~t |dvrq|jdk(rt |dk(r|dnd}|dd}|j J|j jt ||}|jdk(r|fn|}|jj||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 and PA images. See :ref:`colors` for more information. 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. r)r2r3rr3r2rN) r1r{rrrr~rrrr)rr9rr6 palette_indexs r%rzImage.putpixels0  II $54-0E f$yyD $'J!Oabq <<+ ++ LL11%,EM.2ii4.?]E*]EwwE**r$cddlm}|jdvr d}t|d}d}|y|jdk(rN|j |j j }|dk(rd }|j j||}n.td td D}nt|d kDrd }d}d }d gdz}t|D]\} } ||| |z| |z|zz }| || <t|} |j} d| _ |j|| |z| _| j j||dz| jj!| j#d} | j|||j||| _d|j$vr. |j'|j$d| j$d<| S| S#t$rd| j$vr | j$d=Y| SwxYw)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)rrrWr2rrrr3c3&K|] }|dz yw)r2Nr#rrs r%rz&Image.remap_palette..Fs*Fa16*Fsir$rrr_z;Lrr)rrdr{r,r.rrrC bytearrayrr~r5rrrrsrDrrindex) rdest_mapsource_paletterdrr palette_mode palette_bytes new_positionsr oldPositionmapping_palettem_ims r% remap_palettezImage.remap_palette)s # 99J &&CS/ !  !yyC #ww557 6)E!%!3!3L,!O!**F5:*F!F  3 &E!L c (1 +NA{ ^e#kE&9E&A M*+M+ &  +0$M2yy{ 0|00 /E"9   <)R>R>TU||C   |40|00}U TYY & 2,4NN499^;T,U .)  t  2!TYY. .1  2s%+G$G<;G<c t|dz }|d|dz |dz }|d|dz |dz }||z}||z}tdt|d|z tdt|d|z t|jdt j |d|zt|jdt j |d|zfS)zExpands the box so it includes adjacent pixels that may be used by resampling with the given resampling filter. rLr1rr2r )_filters_supportryrrr mathceil) rr resamplerfilter_supportscale_xscale_y support_x support_ys r% _get_safe_boxzImage._get_safe_boxs*(3c9q6CF?d1g-q6CF?d1g-"W, "W,  3s1v )* + 3s1v )* +  ! diiA(:; <  ! diiA(:; <   r$c|tj}n|tjtjtjtjtj tj fvrd|d}tjdftjdftjdftjdftj dftj d ffDcgc]}|d d |d d }}|ddj|ddd|dz }t|||dkr d}t||d|jz}t|}|j|k(r"|d|jzk(r|jS|jdvrtj}|jdvrb|tjk7rO|jddd|j}|j|||}|j|jS|j||tjk7rt!|d|d z |d z |z xsd } t!|d|d z |d z |z xsd } | d kDs| d kDr|j#|t%t||} | | f} t'|j(r|j)| | nt*j)|| | }|d | d z | z |d | d z | z |d| d z | z |d| d z | z f}|j-|j.j|||Scc}w)a Returns a resized copy of this image. :param size: The requested size in pixels, as a tuple or array: (width, height). :param resample: An optional resampling filter. This can be one of :py:data:`Resampling.NEAREST`, :py:data:`Resampling.BOX`, :py:data:`Resampling.BILINEAR`, :py:data:`Resampling.HAMMING`, :py:data:`Resampling.BICUBIC` or :py:data:`Resampling.LANCZOS`. If the image has mode "1" or "P", it is always set to :py:data:`Resampling.NEAREST`. Otherwise, the default filter is :py:data:`Resampling.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. NUnknown resampling filter ().Image.Resampling.NEARESTImage.Resampling.LANCZOSImage.Resampling.BILINEARImage.Resampling.BICUBICImage.Resampling.BOXImage.Resampling.HAMMINGr  (r) Use ,  or rMz#reducing_gap must be 1.0 or greaterrrrrrrr1r2)r)rErJrFrHrKrGrIr~r,r rrr{rresizer.rrzrrreducerwrr) rr rtr reducing_gaprrfiltersrfactor_xfactor_y reduce_boxfactors r%rz Image.resizesZL  !))H              NN      0z.transformz sA!' Q1aAq51q5=1$a!ea!ema&77 7r$r r4rN) fillcolor)rIrr<rrz list[float]rtuple[float, float])r transposer0r9r}r|r8r:r rrradiansrcossinr|rsryfloorrrr>r?)ranglertexpandcenter translaterwr post_transrrxxyyrIr< transformed_x transformed_ynwnhs r%rotatez Image.rotate% sD )zyy{"|~~i&:&:;; !vt{{1J~~+0B;I''!eQU^Fe$$ $((5/2 & $((5/2 &  488E?"B ' $((5/2 &    8 ) AYJA & Z](BF q 6!9 q VAY q VAY BB!Q!Q!Q8 )1/8Av/F, } -( -( )3r7#djjR&99B3r7#djjR&99B $-rAvY_Qi#ov#V F1IvayrqA~~ FI$$fh)  r$c d}d}t|rtj|}d}n.|tjk(r tjj }|s@t|dr4t|jrtj|j}ttjj|dj}t|tr|jn|}|s|t vr t# t |}ddlm} t|| j*rZtjj-|tjj-|j.k(r|j1n|j3|j5d d} ||_t9|d i} |j;|d |_|j?t@vr t#| s)| ?|jCd r.|j?tDvrtD|j?} nt@|j?} d}|r`tjjG| }|jCd drtIjJ|d}n.tIjJ|d}ntMtNt|} | ||| | |_,|r|jSyy#t $rYwxYw#t$$r}d|} t'| |d}~wwxYw#tP$r<|r|jS|r& tjT|#tV$rYwxYwwxYw#| |_,wxYw)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), os.PathLike 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. These can also be set on the image itself through ``encoderinfo``. This is useful when saving multiple images:: # Saving XMP data to a single image from PIL import Image red = Image.new("RGB", (1, 1), "#f00") red.save("out.mpo", xmp=b"test") # Saving XMP data to the second frame of an image from PIL import Image black = Image.new("RGB", (1, 1)) red = Image.new("RGB", (1, 1), "#f00") red.encoderinfo = {"xmp": b"test"} black.save("out.mpo", save_all=True, append_images=[red]) :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. rFTrr zunknown file extension: Nrsave_all encoderinfor# append_imagesr|zr+bzw+b)-rr6fspathr(stdoutbufferrr*rrpathsplitextlowerrrrrqrrr,rrbabspathr>r1r.pop_default_encoderinfor_attach_default_encoderinfo encoderconfigupperrorrpexistsbuiltinsopenrrrUr+removePermissionErrorr)rr"rparamsr>open_fp filename_extextrrrbrr save_handlercreateds r%r9z Image.save s\!# 2;yy}HG 3::  ZZ&&GB/GBGG4Dyy)H ww''1!4::< '1,'Fl!!#L)# -"3  dI// 0RWW__ 6 WW__T]] +6,  " IIK::j$/$*!dM26  ((..0 <<> % F    ?+ (*#FLLN3L /L ''..22Gzz(E*]]8U3]]8U3bi$B + r8 , +D   HHJ Q"    -06 o1, -Z  IIh' '    +D seK2 L L$2 K?>K? L! LL!$M)MM) M$!M)#M$$M))M,, M5cJt|di}i|j||_|S)Nr)rrr)rrrs r%rz!Image._attach_default_encoderinfo s.dM26 Eb55EEr$c(|dk7r d}t|y)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. rzno more images in fileN)EOFError)rframers r%seekz Image.seek s$ A:*C3-  r$c4ddlm}|j||y)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 **xdg-open**, **display**, **gm**, **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. r  ImageShowN)rrshow)rtitlers r%rz Image.show5 s( tU#r$c|j|jjdk(r|jfSt t |j |jjS)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.rrrrr%rrrs r%rz Image.splitM sK 77==A IIK> !SDGGMMO455r$c|jt|tr |jj |}|j |jj|S#t $r}d|d}t ||d}~wwxYw)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.rrrrfr,rrr)rchannelrrs r% getchannelzImage.getchannel` s| gs # ---///8 yy122  -27)1= o1, -sA++ B 4BB cy)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#rs r%tellz Image.tellv sr$rNc tttj| d fd }|}|y|}d}|9j dt |d|zt |d|zf}||d}j |k7rHj||||} | j_|_ jj_ d_ y)an 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: The requested size in pixels, as a 2-tuple: (width, height). :param resample: Optional resampling filter. This can be one of :py:data:`Resampling.NEAREST`, :py:data:`Resampling.BOX`, :py:data:`Resampling.BILINEAR`, :py:data:`Resampling.HAMMING`, :py:data:`Resampling.BICUBIC` or :py:data:`Resampling.LANCZOS`. If omitted, it defaults to :py:data:`Resampling.BICUBIC`. (was :py:data:`Resampling.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 cdd}\jk\rjk\ryjjz z k\r|zfdfS|z fdfS)Nc~tttj|tj||dS)Nkeyr )ryrrrrrs)numberrs r% round_aspectzDImage.thumbnail..preserve_aspect_ratio..round_aspect s+3tzz&1499V3D#NPQRRr$c&t|z z Srr)naspectr<s r%z@Image.thumbnail..preserve_aspect_ratio.. s3vA~;Nr$rc4|dk(rdSt|z z Sr r)rrrIs r%rz@Image.thumbnail..preserve_aspect_ratio.. s16as6APQE>?Rr$)rrrCallable[[int], float]rr)r}r|)rrrIr< provided_sizers @@@r%preserve_aspect_ratioz.Image.thumbnail..preserve_aspect_ratio s S!DAqDJJ1 #3ZZ$++-F1u V1NO a4K!J$Ra4Kr$Nrr )rr)rtuple[int, int] | None) rr%rrrrrr rrrr{rr) rr rtrrpreserved_size final_sizerresrrs ` @r% thumbnailzImage.thumbnail sZc$**d34  "/0  ! #   #**s47\12CQ,8N4OPC!f 99 "ZsVBeeDG#DJDJ r$r c *|jdvra|tjk7rN|jddd|jj ||||||j|jSt |t r|j ||||St|dr|j\}}| d}t|t|j||}|jdk(r+|jr|jj|_ |jj|_ |tjk(r2|D]+\} } |j!| |tj"| ||du-|S|j!d |z|||||du|S) ar 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 in pixels, as a 2-tuple: (width, height). :param method: The transformation method. This is one of :py:data:`Transform.EXTENT` (cut out a rectangular subregion), :py:data:`Transform.AFFINE` (affine transform), :py:data:`Transform.PERSPECTIVE` (perspective transform), :py:data:`Transform.QUAD` (map a quadrilateral to a rectangle), or :py:data:`Transform.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 Implementations of :py:class:`~PIL.Image.ImageTransformHandler` for some of the :py:class:`Transform` methods are provided in :py:mod:`~PIL.ImageTransform`. 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.Transform.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:`Resampling.NEAREST` (use nearest neighbour), :py:data:`Resampling.BILINEAR` (linear interpolation in a 2x2 environment), or :py:data:`Resampling.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:`Resampling.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. rrr)rtfillrNzmissing method datarr)r{rErFrrrImageTransformHandlerr*rr,rrrrr>rC_Image__transformerrB) rr rrfrtrrrrrquads r%rzImage.transform suv 99 &8z7I7I+I D&9$))DE4xyI#  f3 4##D$#M M 69 %!>>+LFD <'CS/ ! D) , 99  **,BJ)).." Y^^ #!  T  y~~tXyD?P     tVT8Y$=N  r$c x|d|dz }|d|dz }|tjk(r|dd}n|tjk(r0|\} } } } | | z |z } | | z |z }tj}| d| d|| f}n|tjk(r|dd}n|tjk(r|dd}|dd}|dd}|dd}|\} } d|z }d|z }| |d| z |z|d| z |z|d|dz |dz | z|z|z| |d| z |z|d| z |z|d|dz |dz | z|z|zf}n d }t ||t jt jt jfvr|t jt jt jfvr?t jd t jd t jd i}||d |dz}nd|d}t jdft jdft jdffDcgc]}|dd |dd}}|ddj|ddd|dz }t ||j|j|jdvrt j}|j j#||j ||||ycc}w)Nr1rr2r r5r3rMzunknown transformation methodrrrrz) cannot be used.r|r}r~rrrrrrrr)r>r?r@rArBr,rErFrHrJrGrIrKr~r.r{rr)rrimagerrfrtrrrrrrrxsysrswseneAsAtrunusablerrs r% __transformerzImage.__transformer7 s. FSVO FSVO Y%% %8D y'' '!NBBr'QBr'QB%%F2q"b)D y,, ,8D y~~ %bqBaBaBaBFBqBqBAr!Ar!AAA&+r1B6Ar!Ar!AAA&+r1B6 D2CS/ !            JNNJ,>,> @R@RSSNN$:&&(B&&(B, x(Rz9J+KK3H:R@  '')CD((*EF'')CD!9+Rq {!,G U499WSb\234 }E ECS/ !  :: #!))H #uxxxF%s J7cv|j|j|jj|S)a Transpose image (flip or rotate in 90 degree steps) :param method: One of :py:data:`Transpose.FLIP_LEFT_RIGHT`, :py:data:`Transpose.FLIP_TOP_BOTTOM`, :py:data:`Transpose.ROTATE_90`, :py:data:`Transpose.ROTATE_180`, :py:data:`Transpose.ROTATE_270`, :py:data:`Transpose.TRANSPOSE` or :py:data:`Transpose.TRANSVERSE`. :returns: Returns a flipped or rotated copy of this image. )r.rrr)rrs r%rzImage.transpose s+ yy**6233r$cv|j|j|jj|S)zj Randomly spread pixels in an image. :param distance: Distance to spread pixels. )r.rr effect_spread)rdistances r%rzImage.effect_spread s+ yy..x899r$cdddlm}|js d}t||j|S)z#Returns a QImage copy of this imager reQt bindings are not installed)rreqt_is_installedrtoqimagerrers r%rzImage.toqimage s1&&1Cc" "w%%r$cdddlm}|js d}t||j|S)z$Returns a QPixmap copy of this imager rr)rrerr toqpixmapr s r%r zImage.toqpixmap s1&&1Cc" " w  &&r$rr)rcore.ImagingCore)rr rrrr)rtuple[int, int]rr)rrrr)rr rrw)NN)r:rrrr;rrr)robjectrr))rOrarPr)rr)rWrrXrr bytes | None)rr)rz.dict[str, str | bytes | int | tuple[int, ...]])rrr)rmz object | Nonerztuple[object, object])r list[Any])rurrrre)rrrrrr)r)rrrr)rf*bytes | bytearray | SupportsArrayInterfacerrrrrr)rzcore.PixelAccess | None) r{rrztuple[float, ...] | Nonerz Dither | NonerrVrrrrw) rrrr+rrr Image | NonerrPrrw)rrw)r(tuple[float, float, float, float] | Nonerrw)rr r!tuple[float, float, float, float]rr )r{rr rrz0tuple[str, tuple[int, int, float, float]] | None)rz-ImageFilter.Filter | type[ImageFilter.Filter]rrw)rtuple[str, ...])rr)r tuple[int, int, int, int] | None)r)rrrzBlist[tuple[int, tuple[int, ...]]] | list[tuple[int, float]] | None)rr+rr )rz1tuple[float, float] | tuple[tuple[int, int], ...]rdict[str, Any])rr)rzlist[ImageFile.ImageFile])rrg)r)rrrzlist[int] | Nonerr))r9tuple[int, int] | list[int]rzfloat | tuple[int, ...] | None)rztuple[list[int], list[int]])r@rrAtuple[float, float] | Noner list[int])r@rrArrr)rz'Image | str | float | tuple[float, ...]rz:Image | tuple[int, int, int, int] | tuple[int, int] | Noner@rrr)rr)rrwrK Sequence[int]rHr!rr)rTzSequence[float] | NumpyArray | Callable[[int], float] | Callable[[ImagePointTransform], ImagePointTransform | float] | ImagePointHandlerr{rrrw)r6z Image | intrr)rMr)rfzISequence[float] | Sequence[Sequence[int]] | core.ImagingCore | NumpyArrayrrrrrr)rfz1ImagePalette.ImagePalette | bytes | Sequence[int]rrrr)r9rrz#float | tuple[int, ...] | list[int]rr)rgr rhzbytes | bytearray | Nonerrw)r rrtrErrrtuple[int, int, int, int])NNN) r z(tuple[int, int] | list[int] | NumpyArrayrtr+rrr float | Nonerrw)rzint | tuple[int, int]rrrrw)rrrtrErz int | boolrrrrr&float | tuple[float, ...] | str | Nonerrw)r"StrOrBytesPath | IO[bytes]rrrrrr)rrwrr)rrrr)rrrr)rztuple[Image, ...])rz int | strrrw)r rrtrErr#rr)r rrz3Transform | ImageTransformHandler | SupportsGetDatarfzSequence[Any] | Nonertrrrrr$rrw)rr"rrwrr>rfzSequence[float]rtrrr)rr)rr0rrw)rrrrw)rzImageQt.ImageQt)rImageQt.QPixmap)br r!r"rr__annotations__r!_close_exclusive_fp_after_loadingrpropertyrsetterr}r|r r{rrrr#r+r/r1r?rErLrQrZr_rbrgrirkrprvrDrrtr.rrVrWrrPrTrr__copy__rrrrrrrrrrr'r)r,r/rCr3r7rr;rrCrGrJrRr[r]rsrrorzrrrErFrr9rrrrrrrJrrrrrrr r#r$r%rwrwsI FJ%) )(,%' YYBB__""  J( =A/9MP 0     9(  , 15K -K K M 7 r :"#"8#"#" #"  #"J"H   +/ $";; ~~)~ ~  ~  ~ ~D! $.. QQQ Q  Q  Q Qf )H34)"))J) ),  &< 9 2%62-1+( #,, K,2. $%5N$L : 7,*&0 +- + ' +  PT# #2L# #DPT! !2L! !>KO! Z' 3Z'HZ' Z'  Z'zPV6 6 ,6 ?L6 6 B :7 :7:7 :7x5(t -W-- -  -6)?))  )V&+!&+*M&+ &+ROSX!X3KX Xt   /  #  2 $8<%) g>6g>g>6 g> # g>  g>X15!6%!6.!6  !6L *11"-1,0<@r r r  r + r * r :r  r jDH,6@SV B  ,$06&3,  *11%( T!TT# T  Tx&*"**<@\\D\# \  \  \:\ \H#**TG &TGTG TG  TG  TGTG TGl 4:&'r$c6eZdZdZej ddZy)rQzb Used as a mixin by point transforms (for use with :py:meth:`~PIL.Image.Image.point`) cyrr#r s r%rRzImagePointHandler.point s r$N)rrwrrw)r r!r"rabcabstractmethodrRr#r$r%rQrQ s!    r$rQcFeZdZdZej ddZy)rzi Used as a mixin by geometry transforms (for use with :py:meth:`~PIL.Image.Image.transform`) c yrr#)rr rr;s r%rzImageTransformHandler.transform s r$N)r rrrwr;rrrw)r r!r"rr.r/rr#r$r%rr sG          r$rct|ttfs d}t|t |dk7r d}t||ddks|ddkr d}t|y)z Common check to enforce type and sanity check on size tuples :param size: Should be a 2 tuple of (width, height) :returns: None, or raises a ValueError zSize must be a list or tupler1z#Size must be a sequence of length 2rr zWidth and height must be >= 0N)rrrr,r~)r rs r% _check_sizer3 sd dT5M *,o 4yA~3o Aw{d1gk-o"r$cjt||-tjtj||St |t rddlm}|j||}t}|dk(rt |ttfrtd|Drutttdft|}t|dk(st|dk(r7ddlm}|j |_|j"j|}|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 or HSV images, you can also use color strings as supported by the ImageColor module. See :ref:`colors` for more information. If the color is None, the image is not initialised. :returns: An :py:class:`~PIL.Image.Image` object. r rErc3<K|]}t|tywr)rrrds r%rznew.. s2q 1c"2s.r2r3r)r3rwrrrrrrrFrrrallrrr~rdrr)r{r colorrFr color_intsrds r%rr s( }w||DHHT4011% !##E40 B  utUm , 2E2 2&*5c?E%L&I z?a 3z?a#7 &2224BJJJ'' 3E 77499T4/ 00r$ct|t||}|jdk7rV|jdk7rG|}t |dk(rt |dt r|d}|dk(r|dk(r|}|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 Codec `. 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. rr rer#)r3rr}r|r~rrrt)r{r rfrrrrs r%rtrt s}< T4B xx1}a |  !ja%&H'?L 5 \R%7L T<6 Ir$c t|t|dk(rt|dtr|d}|dk(r|dk(r|ddf}|dtvryt |d}|j tj|||d|}|dk(r7ddl m }|jd|jjd|_ 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. 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 r rrer#rrrr)r3r~rr _MAPMODESrrr map_bufferrrdrrCrrrt)r{r rfrrrrds r% frombufferr=L sP 4yA~*T!We4Awu 2:A:D 7i T6"Bt\1dKLBs{*6\66ubee>N>Nu>UV BKI T4|T ::r$c"eZdZdZeddZy)SupportsArrayInterfacezC An object that has an ``__array_interface__`` dictionary. ctrNotImplementedErrorrs r%rgz*SupportsArrayInterface.__array_interface__ s !##r$Nr)r r!r"rr)rgr#r$r%r?r? s$$r$r?c"eZdZdZ d ddZy)SupportsArrowArrayInterfacezm An object that has an ``__arrow_c_array__`` method corresponding to the arrow c data interface. NctrrArls r%rkz-SupportsArrowArrayInterface.__arrow_c_array__ s "##r$r)rmz 'PyCapsule'rztuple['PyCapsule', 'PyCapsule'])r r!r"rrkr#r$r%rDrD s! /3$ +$ ($r$rDc |j}|d}t|}|jdd} d|ddz|df}| t |\} } }|| k7r|vr t d d |} n }|d vrd}n |d k(rd}nd}||kDrd|d|d} t| |dk(rdn|d|df}|Gt|dr|j}n*t|dr|j}n d} t| t|||d ddS#t$r}|d}g}nd} t | |Yd}~d}~wwxYw#t$r}|\} } d| d | } t | |d}~wwxYw)a2 Creates an image memory from an object exporting the array interface (using the buffer protocol):: from PIL import Image import numpy as np a = np.zeros((5, 5)) im = Image.fromarray(a) If ``obj`` is not contiguous, then the ``tobytes`` method is called and :py:func:`~PIL.Image.frombuffer` is used. In the case of NumPy, be aware that Pillow modes do not always correspond to NumPy dtypes. Pillow modes only offer 1-bit pixels, 8-bit pixels, 32-bit signed integer pixels, and 32-bit floating point pixels. Pillow images can also be converted to arrays:: from PIL import Image import numpy as np im = Image.open("hopper.jpg") a = np.asarray(im) When converting Pillow images to arrays however, only pixel values are transferred. This means that P and PA mode images will lose their palette. :param obj: Object with array interface :param mode: Optional mode to use when reading ``obj``. Since pixel values do not contain information about palettes or color spaces, this can be used to place grayscale L mode data within a P mode image, or read RGB data as YCbCr for example. See: :ref:`concept-modes` for general information about modes. :returns: An image object. .. versionadded:: 1.1.6 rstridesNrr1rzCannot handle this data typezCannot handle this data type: rz('mode' parameter for changing data typesr+)rrrrrrr2r3zToo many dimensions: z > rr rrDtostringz1'strides' requires either tobytes() or tostring()re) rgr~rrr_fromarray_typemaprr,r*rDrHr=)objr{rrndimrGtypekeyr color_modesrtypemoder typekey_shaperndmaxr s r% fromarrayrQ sL  ! !C LE u:Dggi&G(59$c)n4 (-?-H *Hg{   8 K 7 @" E ((  e|%dV3ugQ7o 1uQxq 1D 3 "++-C S* %,,.CECS/ ! dD#ugq! < D)> D&D!!D&) E2E  Ect|ds d}t||j\}}tj||||}|rt j |Sd}t|)aCreates an image with zero-copy shared memory from an object exporting the arrow_c_array interface protocol:: from PIL import Image import pyarrow as pa arr = pa.array([0]*(5*5*4), type=pa.uint8()) im = Image.fromarrow(arr, 'RGBA', (5, 5)) If the data representation of the ``obj`` is not compatible with Pillow internal storage, a ValueError is raised. Pillow images can also be converted to Arrow objects:: from PIL import Image import pyarrow as pa im = Image.open('hopper.jpg') arr = pa.array(im) As with array support, when converting Pillow images to arrays, only pixel values are transferred. This means that P and PA mode images will lose their palette. :param obj: Object with an arrow_c_array interface :param mode: Image mode. :param size: Image size. This must match the storage of the arrow object. :returns: An Image object Note that according to the Arrow spec, both the producer and the consumer should consider the exported array to be immutable, as unsynchronized updates will potentially cause inconsistent data. See: :ref:`arrow-support` for more detailed information .. versionadded:: 11.2.1 rkz!arrow_c_array interface not foundz,new_arrow returned None without an exception)r*r,rkr new_arrowrwr)rJr{r rschema_capsule array_capsulers r% fromarrowrV siN 3+ ,1o&)&;&;&=#^] ..t^] CC w||C  8C S/r$cdddlm}|js d}t||j|S)z-Creates an image instance from a QImage imager rr)rrerr fromqimagerrers r%rXrX+ s1  " "-# 7  b !!r$cdddlm}|js d}t||j|S)z.Creates an image instance from a QPixmap imager rr)rrerr fromqpixmaprYs r%r[r[5 s1  " "-# 7  r ""r$)rz|b1rz1;8)r|u1rr)rz|i1rzI;8)rzu2r)rzi2zI;16BS)rzu4zI;32B)rzi4zI;32BS)rzf4zF;32BF)rzf8zF;64BF))r r r1r\rrr))r r r2r\r)rrr))r r r3r\r)rrrri4f4ctytd|dtd|dz}|dtzkDrd|ddtzd}t||tkDr&tjd|dtdt yy)Nr rr1z Image size (z pixels) exceeds limit of z0 pixels, could be decompression bomb DOS attack.)r,ryr(rrr)r pixelsrs r%rrZ s DG_s1d1g .F $$$6(" > %S))    6("<=MprefixformatsrfactoryacceptrOrr exclusive_fpwarning_messagess r% _open_corezopen.._open_core s  A A} "&q'#5vf~fc*$++F3GGAJ X.B-bgg6I * Y E N($++A0C,Cc!f,LM  HHJ sA-B#D &C++ D c3,K|] }|vs| ywrr#)rrchecked_formatss r%rzopen.. sTfO6SfTs zcannot identify image file %r) r" IO[bytes]r>z str | bytesrjrrkzlist[str] | tuple[str, ...]rzImageFile.ImageFile | None)reprr,rrSStringIOrkrrrrr6rrrrrrrrUnsupportedOperationrTreadrrrr r+rrr ) r"r{rkrr>rjrprmessagerrrnros @@@r%rro sD s{$t*&o B $ 0 o $ //nLHr{99R= ]]8T * "U)R   WWR[F I"$ -  $ : B&' 2B zgm'') 6T7TT B '   # g )Xr JC  %%y B33 4 ZZ " s F&&>G('G(c|j|j|jtj|j|jS)z Alpha composite im2 over im1. :param im1: The first image. Must have mode RGBA or LA. :param im2: The second image. Must have the same mode and size as the first image. :returns: An :py:class:`~PIL.Image.Image` object. )r.rrrJr)im1im2s r%rJrJ s:HHJHHJ 88D((8 99r$c|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.rrblendr)rzr{r6s r%r}r} s:$HHJHHJ 88DJJsvvsvvu5 66r$cL|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)rrG)image1image2r@rs r% compositers$ KKME KKd# Lr$c*|j|dS)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)rR)rrs r%evalr%s ;;tAw r$c t|t|k7sd|vr d}t||ddD]P}|jt |k7r d}t||j |dj k7sEd}t||D]}|j |djtj|g|Dcgc]}|jc}Scc}w)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 bandsr Nz mode mismatchrz size mismatch) rr~r,r{rr r.rrrr)r{rrrrYs r%rr5sDSZ'3$;%oab " 99 D) )!CS/ ! 99a %!CS/ ! "  8==DA%+@QADD+@A BB+@s;Cct|j}|tvrtj|||ft|<y)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)rrkr|rl)rKrlrms r% register_openrTs." B | " DHr$c2|t|j<y)a Registers an image MIME type by populating ``Image.MIME``. This function should not be used in application code. ``Image.MIME`` provides a mapping from image format identifiers to mime formats, but :py:meth:`~PIL.ImageFile.ImageFile.get_format_mimetype` can provide a different result for specific images. :param id: An image format identifier. :param mimetype: The image MIME type for this format. N)rnr)rKmimetypes r% register_mimerks Dr$c2|t|j<y)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)rorrKdrivers r% register_saverzsDr$c2|t|j<y)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)rprrs r%register_save_allrs"HRXXZr$cN|jt|j<y)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)rrqr)rK extensions r%register_extensionrs$&88:Iioo r$c*|D]}t||y)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)rK extensionsrs r%register_extensionsrs * 2y)*r$c"ttS)za Returns a dictionary containing all file extensions belonging to registered plugins )rrqr#r$r%registered_extensionsrs  F r$c|t|<y)z Registers an image decoder. This function should not be used in application code. :param name: The name of the decoder :param decoder: An ImageFile.PyDecoder object .. versionadded:: 4.1.0 N)rr)rrs r%register_decoderr HTNr$c|t|<y)z Registers an image encoder. This function should not be used in application code. :param name: The name of the encoder :param encoder: An ImageFile.PyEncoder object .. versionadded:: 4.1.0 N)rs)rrs r%register_encoderrrr$c Pddlm}tddd|j|fi|y)Nr rz Image._showr+zImageShow.show)rrrr)rr;rs r%_showrs% mR!12INN5$G$r$c^tjtj|||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, y1). :param quality: Quality. )rwrreffect_mandelbrot)r extentqualitys r%rrs$ 7<<..tVWE FFr$c\tjtj||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. )rwrr effect_noise)r sigmas r%rrs" 7<<))$6 77r$cZtjtj|S)zl Generate 256x256 linear gradient from black to white, top to bottom. :param mode: Input mode. )rwrrlinear_gradientrs r%rr 7<<,,T2 33r$cZtjtj|S)zm Generate 256x256 radial gradient from black to white, centre to edge. :param mode: Input mode. )rwrrradial_gradientrs r%rrrr$c||ntj}dtjfdtjfdtj ffD]d\}}||vr ||j }d}dD](\}}|j|s|}|dt| }* t||z} ||fy#t$rtj|dYwxYw#t$r$} tj|d| Yd} ~ d} ~ wwxYw)NPILLOW_ALIGNMENTPILLOW_BLOCK_SIZEPILLOW_BLOCKS_MAXr ))r i)riz is not intz: ) r6environr set_alignmentset_block_sizeset_blocks_maxrr7r~rr,rr) envenv_dictvar_namer*varunitspostfixmulvar_intrs r%_apply_env_variablesrsos2::H T//0 d112 d112.& 8 # x &&(= +LGS||G$/S\M* +  #h&G  . 7O/.$  MMXJk2 3    . MMXJb, - - .s*B2'C2!CC D"DDceZdZUdZdZded<dZdZddZddZ ddZ d dd Z dd Z dd Z ddd Zd d Zd!d"dZd#dZddZd$dZd%dZd&dZd'dZd(dZd)dZd*dZy)+ra This class provides read and write access to EXIF image data:: from PIL import Image im = Image.open("exif.png") exif = im.getexif() # Returns an instance of this class Information can be read and written, iterated over or deleted:: print(exif[274]) # 1 exif[274] = 2 for k, v in exif.items(): print("Tag", k, "Value", v) # Tag 274 Value 2 del exif[274] To access information beyond IFD0, :py:meth:`~PIL.Image.Exif.get_ifd` returns a dictionary:: from PIL import ExifTags im = Image.open("exif_gps.jpg") exif = im.getexif() gps_ifd = exif.get_ifd(ExifTags.IFD.GPSInfo) print(gps_ifd) Other IFDs include ``ExifTags.IFD.Exif``, ``ExifTags.IFD.MakerNote``, ``ExifTags.IFD.Interop`` and ``ExifTags.IFD.IFD1``. :py:mod:`~PIL.ExifTags` also has enum classes to provide names for data:: print(exif[ExifTags.Base.Software]) # PIL print(gps_ifd[ExifTags.GPS.GPSDateStamp]) # 1999:99:99 99:99:99 NrrFcJi|_i|_i|_d|_d|_yr)_data _hidden_data_ifds_info _loaded_exifrs r%rz Exif.__init__]s'%' ,.02 CG *.r$cn t|dk(rt|tr|dS|S#t$rY|SwxYwr)r~rrrU)rrs r%_fixupz Exif._fixupdsD 5zQ:eU#;Qx     s "' 44ct|jDcic]\}}||j|c}}Scc}}wr)rr)rsrc_dictr rs r% _fixup_dictzExif._fixup_dictls0/7nn.>?da4;;q>!???s4c |jj|ddlm}|j|j |}|j |j|jt|S#ttf$rYywxYw)Nr rf)group) r"rrrfImageFileDirectory_v2headr.rdictrr)rrrrfrs r% _get_ifd_dictzExif._get_ifd_dictqst 0 GGLL  *8?88%PD IIdgg ##DJ/ /)$  sA66BBc|jrdnd}|jdk(rd|zdztdz}nd|ztdz}|jr-||jdk(r tdn tdz }|dz }|S) N+*rusIIrsMMs)rrrr)rrdrs r% _get_headzExif._get_heads{!\\'w ;;# 7?W,uQx7Dw&q1D <<  s 2E!Ha @D ' 'D r$c||jk(ry||_|jj|jj|jj|r*|j dr|dd}|r|j dr|sd|_ytj||_ |jjd|_ ddl m }|j|j|_|j j|_|jj#|j j$|j j'|jy)NExifr5rr r)rrclearrr startswithrrSrTr"rwrrrfrrrrnextr.)rrfrfs r%r.z Exif.loads 4$$ $    ! t78Dt7DJ ZZ-GGLLO %:_::499E jj((   TZZ__%  r$cd|_|jj|jj|jjddlm}||_||j|_ n |jjd|_ |j|j|_ |j|jj|_ ||jj}|jj!|jj#||jj%|jy)Nr rr)rrrrrrrfr"rrrwrrrrrrrr.)rr"rrfs r%rzExif.load_from_fps   !  &  (DI QDI:_::499E ;; **,,DK >ZZ__F    V  r$ct|}tjj|vrX|j |tjjtjj}|r|j |tjj |vr`|j |tjj tjj |tjj <|Sr)rr IFDrrupdateGPSInfo)r merged_dictifds r%_get_merged_dictzExif._get_merged_dicts4j  <<   $$$T(,,*;*;%O>OPC""3' <<  4 '040B0BX\\))*HLL,@,@1K ,, -r$c6ddlm}|j}|j|}|jj D]\}}||vs |||<|j D]\}}|t jjt jjfvrt|ts|j|}|t jjk(rt jj|vrt|t jjtsT|j}|jt jj|t jj<|||<d|z|j|zS)Nr r)ifhr)rrfrrrrr rrrrrget_ifdInteroprrD)rrrfrrrifd_dictrs r%rDz Exif.tobytessB%~~3o33=!ZZ--/ $MC$#C $**, JC !! $$!- S)8<<,,, ,,5&uX\\-A-A'BDI!JJLE26,,x||?S?S2TE(,,../CH % F(;;;r$c  ||jvr0|tjjk(r`|j|jj dk7r|j |jj }|||j|<n|tjjtjjfvrT|jj||j|}|O|j ||}|:||j|<n)|tjjtjjfvrtjj|jvr)|jtjj|jtjj|}|tjjk(r8ddlm}|j!dr't#|d}||d}i}t%t'j(d|dddD]} t'j(d|| d zdz| dzd zdz\} } } } |j*| \}}| |z}|d kDr't'j(d | \}||d z ||zd z } n| d|} t/| |k7r(t1j2d |d t/| d| | s||| d|| <t5|j7||j|<n|jddk(ri}t%t'j(d|dddD]} t'j(d|| d zdz| dzd zdz\} } } } | dk(s7t'j(d| \}|j8j;|d|j8j=d i}|j8j=d t#|j8j=d |d<|j8j=d |j8j=d |d<|j8j=d |j8j=d }|j*t>j@d}|||dd|d<|j8j=d |j8j=d|d<d|i}||j|<n#|j ||}|||j|<|jjC|i}|tjjk(re|jrY|jEDcic]>\}}|tjjtjjfvr||@}}}|S#t,$rYwxYwcc}}w)Nrr )rsFUJIFILMrzHz>HHL4siz>LModelID TimeStampInternalSerialNumberParallaxCategory)#rr rIFD1rrrrrrrr MakerNoterrfrrrrrgunpack_load_dispatchrr~rrrrr"rrwr FLOAT setdefaultr)rrrrtag_datar ifd_offsetifd_data makernoterifd_tagtypcountrf unit_sizehandlerr  camerainfoparallaxr rs r%rz Exif.get_ifdsA djj hll'''::)djjoo.B,,TZZ__=C*- 3**HLL,@,@AA**..sDHHSMB%,,VS9C*- 3--x||/E/EFF<<$$DJJ6LL!2!23::hll&7&78=(,,000F**;7%*8Q%7 #+JK#8$& !&v}}T8BQ<'H'K!LA8> ((1r6A:Q" q@P*Q95GS%)%:$H$H$M!"$-$+$)9#4D#ax,2MM$,E '/ ftmb>P'Q'+ET{"4yD0 ( %99=>R'*4yk %K!" !)#' (18 5 7u2Ig.;@+/t/?/? /J*K 3&)Z7$& !&v}}T8BQ<'H'K!L AA8> ((1r6A:Q" q@P*Q95GS% '&0,2MM$,E  $ V 4%.tww||AF" !% Q:? R@P:Q ; 7 $ QEIWW\\RS_ +A B $ R 0+/77<<?*?*N*N$,NN+""#+%:A$9$;Xu:""#:% : 6!% Q9=a : 6-3Z,@ A AB+4 3,,Xs;C*- 3jj##C, (,,## #(9(9"iikQX\\118<<3I3IJJ1C  Q$,) ()Fs&W AW0 W-,W-ctjjtjjfD]}||vs|||j|<||=yr)r rrrrrrs r% hide_offsetszExif.hide_offsetsUsLLL%%x||';';< Cd{)-c!!#&I r$cp|j|jD]}|| t|jSr)rrrrs r%__str__z Exif.__str__[s6 :: !zz S  4::r$ct|j}|j|j|jt |Sr)setrrrr~rkeyss r%__len__z Exif.__len__cs34:: :: ! KK #4yr$c|jT||jvrF||jvr8|j|j||j|<|j|=|j|Sr)rrrrs r% __getitem__zExif.__getitem__isY :: !c&;tzz@Q"kk$**S/:DJJsO 3zz#r$c^||jvxs|jduxr||jvSr)rrrs r% __contains__zExif.__contains__os-djj RTZZt%;%Qtzz@QRr$cp|j||jvr |j|=||j|<yr)rr)rrrs r% __setitem__zExif.__setitem__rs/ :: !cTZZ&7 3 3r$c|j||jvr|j|=y|j|=||jvr|j|=yyr)rrrrs r% __delitem__zExif.__delitem__wsI :: !cTZZ&7 3 3djj JJsO!r$ct|j}|j|j|jt |Sr)rrrriterrs r%__iter__z Exif.__iter__s34:: :: ! KK #Dzr$r )rrrr)rdict[int, Any]rrr)rrrr+rzdict[int, Any] | None)rr)rfrrr)r"rsrr+rr)rr)r)rrrr)rrrrrr)rrrr)rrrr))rrrrrr)rrrr)rz Iterator[int])r r!r"rrr'rrrrrrrr.rrrDrrrr r r rrrr#r$r%rr7sBFJGG/@ 0400",0 0 !:!."<0jX   S $r$r)rrwrztuple[tuple[int, ...], str])r{rrr)r{rrr)r{rrrr r)r#) r{rrrrrrtuple[Any, ...]rz)core.ImagingDecoder | ImageFile.PyDecoder) r{rrrrrrrrz)core.ImagingEncoder | ImageFile.PyEncoder)rzrErGrHrIrJrKrqrPrVrZmodulesmoduleitemsetattrrrr*r_FILTERED HUFFMAN_ONLYRLEFIXEDmmapxml.etree.ElementTreer`IPython.lib.prettyrarbrcrdrerf_typingrgrhrirkrlrnrorprqrrrs byteorder_ENDIANrMODESr;rrrrrrrrrrrrrwABCrQrr3rrtr=r?rDrQrVrXr[rIrrrJr}rrrrrrrrrrrrrrrrrrregister clear_cache _ExifBaserr#r$r%r9sG6#   *%% )(!) & << #   8 $ ~  Y $t# ##?@*@ #gd$4d;; $T+;TBCD*m - # <<  NNC Wg w X   :vw I/D/ 4::.//  4#$,,}}H$$L ((C JJE  -0PP@@I nCE@EGI DI >13 .313 .3 (*# 2 I  , , ). *Z@GI( ( ((+(4C(.(4GI( ( ((+(4C(.(:'L'LTQ FQQ.h. p&'p&'nM    CGG  (,56.1 .1 %.1 2.1 .1j + + + 5+ +  +  +d ;; ;; ;; );; ;;  ;;  ;;|$X$ $( $T=n1 $1,/17F1 1h"#c5"%c3&  c5"%  c62& c7B'c7B'c8R(c62&c7B'c7B'c8R(c7B'c8R( c7B'!"c8R(#$tdD\2%&'>?'()AB y^sCn y^sCn/6 .26y&"y& y&0y& y&@ :7."  CJ48   $ 1  .     D    "  "D "  ". *  "% G  G#D GOR G  G844.>  !sCx(IIL9LqwKT  1v/0  M   Q  3 4 c!fn-  s+<S+SS  S T6AT11T6