当前位置:网站首页>PIL pilot image processing [1] - installation and creation

PIL pilot image processing [1] - installation and creation

2022-06-11 19:09:00 html_ finder

----------- I'm sorry , The catalog doesn't seem to work --------- Change to 2022.5.30 21 when

Catalog

-1-Download install

1. open command(cmd) window

2. Input instruction :

error :

correct :

-2-import Import

-3- All the files

-4-Create- Create a new picture .

-MODE-

-SIZE-

-COLOR-

-5- When you want to change the picture format 【 See above 】 when .

Source code :

brief introduction :

Use

 -6- When you want to open a picture


-1-Download install

1. open command(cmd) window

2. Input instruction :

error :

pip install PIL

result :

ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)
ERROR: No matching distribution found for PIL

---

correct :

pip install Pillow

-2-import Import

What's interesting is that , Import requires input :

import PIL

perhaps

from PIL import *

Single file :

from PIL import ...

-3- All the files

See for yourself !

|-PIL 		---<dir>
|	|-BdfFontFile.py 		---<file>
|	|-BlpImagePlugin.py 		---<file>
|	|-BmpImagePlugin.py 		---<file>
|	|-BufrStubImagePlugin.py 		---<file>
|	|-ContainerIO.py 		---<file>
|	|-CurImagePlugin.py 		---<file>
|	|-DcxImagePlugin.py 		---<file>
|	|-DdsImagePlugin.py 		---<file>
|	|-EpsImagePlugin.py 		---<file>
|	|-ExifTags.py 		---<file>
|	|-features.py 		---<file>
|	|-FitsStubImagePlugin.py 		---<file>
|	|-FliImagePlugin.py 		---<file>
|	|-FontFile.py 		---<file>
|	|-FpxImagePlugin.py 		---<file>
|	|-FtexImagePlugin.py 		---<file>
|	|-GbrImagePlugin.py 		---<file>
|	|-GdImageFile.py 		---<file>
|	|-GifImagePlugin.py 		---<file>
|	|-GimpGradientFile.py 		---<file>
|	|-GimpPaletteFile.py 		---<file>
|	|-GribStubImagePlugin.py 		---<file>
|	|-Hdf5StubImagePlugin.py 		---<file>
|	|-IcnsImagePlugin.py 		---<file>
|	|-IcoImagePlugin.py 		---<file>
|	|-Image.py 		---<file>
|	|-ImageChops.py 		---<file>
|	|-ImageCms.py 		---<file>
|	|-ImageColor.py 		---<file>
|	|-ImageDraw.py 		---<file>
|	|-ImageDraw2.py 		---<file>
|	|-ImageEnhance.py 		---<file>
|	|-ImageFile.py 		---<file>
|	|-ImageFilter.py 		---<file>
|	|-ImageFont.py 		---<file>
|	|-ImageGrab.py 		---<file>
|	|-ImageMath.py 		---<file>
|	|-ImageMode.py 		---<file>
|	|-ImageMorph.py 		---<file>
|	|-ImageOps.py 		---<file>
|	|-ImagePalette.py 		---<file>
|	|-ImagePath.py 		---<file>
|	|-ImageQt.py 		---<file>
|	|-ImageSequence.py 		---<file>
|	|-ImageShow.py 		---<file>
|	|-ImageStat.py 		---<file>
|	|-ImageTk.py 		---<file>
|	|-ImageTransform.py 		---<file>
|	|-ImageWin.py 		---<file>
|	|-ImImagePlugin.py 		---<file>
|	|-ImtImagePlugin.py 		---<file>
|	|-IptcImagePlugin.py 		---<file>
|	|-Jpeg2KImagePlugin.py 		---<file>
|	|-JpegImagePlugin.py 		---<file>
|	|-JpegPresets.py 		---<file>
|	|-McIdasImagePlugin.py 		---<file>
|	|-MicImagePlugin.py 		---<file>
|	|-MpegImagePlugin.py 		---<file>
|	|-MpoImagePlugin.py 		---<file>
|	|-MspImagePlugin.py 		---<file>
|	|-PaletteFile.py 		---<file>
|	|-PalmImagePlugin.py 		---<file>
|	|-PcdImagePlugin.py 		---<file>
|	|-PcfFontFile.py 		---<file>
|	|-PcxImagePlugin.py 		---<file>
|	|-PdfImagePlugin.py 		---<file>
|	|-PdfParser.py 		---<file>
|	|-PixarImagePlugin.py 		---<file>
|	|-PngImagePlugin.py 		---<file>
|	|-PpmImagePlugin.py 		---<file>
|	|-PsdImagePlugin.py 		---<file>
|	|-PSDraw.py 		---<file>
|	|-PyAccess.py 		---<file>
|	|-SgiImagePlugin.py 		---<file>
|	|-SpiderImagePlugin.py 		---<file>
|	|-SunImagePlugin.py 		---<file>
|	|-TarIO.py 		---<file>
|	|-TgaImagePlugin.py 		---<file>
|	|-TiffImagePlugin.py 		---<file>
|	|-TiffTags.py 		---<file>
|	|-WalImageFile.py 		---<file>
|	|-WebPImagePlugin.py 		---<file>
|	|-WmfImagePlugin.py 		---<file>
|	|-XbmImagePlugin.py 		---<file>
|	|-XpmImagePlugin.py 		---<file>
|	|-XVThumbImagePlugin.py 		---<file>
|	|-_binary.py 		---<file>
|	|-_imaging.cp39-win_amd64.pyd 		---<file>
|	|-_imagingcms.cp39-win_amd64.pyd 		---<file>
|	|-_imagingft.cp39-win_amd64.pyd 		---<file>
|	|-_imagingmath.cp39-win_amd64.pyd 		---<file>
|	|-_imagingmorph.cp39-win_amd64.pyd 		---<file>
|	|-_imagingtk.cp39-win_amd64.pyd 		---<file>
|	|-_tkinter_finder.py 		---<file>
|	|-_util.py 		---<file>
|	|-_version.py 		---<file>
|	|-_webp.cp39-win_amd64.pyd 		---<file>
|	|-__init__.py 		---<file>
|	|-__main__.py 		---<file>
|	|-__pycache__ 		---<dir>
|	|	|-BdfFontFile.cpython-39.pyc 		---<file>
|	|	|-BlpImagePlugin.cpython-39.pyc 		---<file>
|	|	|-BmpImagePlugin.cpython-39.pyc 		---<file>
|	|	|-BufrStubImagePlugin.cpython-39.pyc 		---<file>
|	|	|-ContainerIO.cpython-39.pyc 		---<file>
|	|	|-CurImagePlugin.cpython-39.pyc 		---<file>
|	|	|-DcxImagePlugin.cpython-39.pyc 		---<file>
|	|	|-DdsImagePlugin.cpython-39.pyc 		---<file>
|	|	|-EpsImagePlugin.cpython-39.pyc 		---<file>
|	|	|-ExifTags.cpython-39.pyc 		---<file>
|	|	|-features.cpython-39.pyc 		---<file>
|	|	|-FitsStubImagePlugin.cpython-39.pyc 		---<file>
|	|	|-FliImagePlugin.cpython-39.pyc 		---<file>
|	|	|-FontFile.cpython-39.pyc 		---<file>
|	|	|-FpxImagePlugin.cpython-39.pyc 		---<file>
|	|	|-FtexImagePlugin.cpython-39.pyc 		---<file>
|	|	|-GbrImagePlugin.cpython-39.pyc 		---<file>
|	|	|-GdImageFile.cpython-39.pyc 		---<file>
|	|	|-GifImagePlugin.cpython-39.pyc 		---<file>
|	|	|-GimpGradientFile.cpython-39.pyc 		---<file>
|	|	|-GimpPaletteFile.cpython-39.pyc 		---<file>
|	|	|-GribStubImagePlugin.cpython-39.pyc 		---<file>
|	|	|-Hdf5StubImagePlugin.cpython-39.pyc 		---<file>
|	|	|-IcnsImagePlugin.cpython-39.pyc 		---<file>
|	|	|-IcoImagePlugin.cpython-39.pyc 		---<file>
|	|	|-Image.cpython-39.pyc 		---<file>
|	|	|-ImageChops.cpython-39.pyc 		---<file>
|	|	|-ImageCms.cpython-39.pyc 		---<file>
|	|	|-ImageColor.cpython-39.pyc 		---<file>
|	|	|-ImageDraw.cpython-39.pyc 		---<file>
|	|	|-ImageDraw2.cpython-39.pyc 		---<file>
|	|	|-ImageEnhance.cpython-39.pyc 		---<file>
|	|	|-ImageFile.cpython-39.pyc 		---<file>
|	|	|-ImageFilter.cpython-39.pyc 		---<file>
|	|	|-ImageFont.cpython-39.pyc 		---<file>
|	|	|-ImageGrab.cpython-39.pyc 		---<file>
|	|	|-ImageMath.cpython-39.pyc 		---<file>
|	|	|-ImageMode.cpython-39.pyc 		---<file>
|	|	|-ImageMorph.cpython-39.pyc 		---<file>
|	|	|-ImageOps.cpython-39.pyc 		---<file>
|	|	|-ImagePalette.cpython-39.pyc 		---<file>
|	|	|-ImagePath.cpython-39.pyc 		---<file>
|	|	|-ImageQt.cpython-39.pyc 		---<file>
|	|	|-ImageSequence.cpython-39.pyc 		---<file>
|	|	|-ImageShow.cpython-39.pyc 		---<file>
|	|	|-ImageStat.cpython-39.pyc 		---<file>
|	|	|-ImageTk.cpython-39.pyc 		---<file>
|	|	|-ImageTransform.cpython-39.pyc 		---<file>
|	|	|-ImageWin.cpython-39.pyc 		---<file>
|	|	|-ImImagePlugin.cpython-39.pyc 		---<file>
|	|	|-ImtImagePlugin.cpython-39.pyc 		---<file>
|	|	|-IptcImagePlugin.cpython-39.pyc 		---<file>
|	|	|-Jpeg2KImagePlugin.cpython-39.pyc 		---<file>
|	|	|-JpegImagePlugin.cpython-39.pyc 		---<file>
|	|	|-JpegPresets.cpython-39.pyc 		---<file>
|	|	|-McIdasImagePlugin.cpython-39.pyc 		---<file>
|	|	|-MicImagePlugin.cpython-39.pyc 		---<file>
|	|	|-MpegImagePlugin.cpython-39.pyc 		---<file>
|	|	|-MpoImagePlugin.cpython-39.pyc 		---<file>
|	|	|-MspImagePlugin.cpython-39.pyc 		---<file>
|	|	|-PaletteFile.cpython-39.pyc 		---<file>
|	|	|-PalmImagePlugin.cpython-39.pyc 		---<file>
|	|	|-PcdImagePlugin.cpython-39.pyc 		---<file>
|	|	|-PcfFontFile.cpython-39.pyc 		---<file>
|	|	|-PcxImagePlugin.cpython-39.pyc 		---<file>
|	|	|-PdfImagePlugin.cpython-39.pyc 		---<file>
|	|	|-PdfParser.cpython-39.pyc 		---<file>
|	|	|-PixarImagePlugin.cpython-39.pyc 		---<file>
|	|	|-PngImagePlugin.cpython-39.pyc 		---<file>
|	|	|-PpmImagePlugin.cpython-39.pyc 		---<file>
|	|	|-PsdImagePlugin.cpython-39.pyc 		---<file>
|	|	|-PSDraw.cpython-39.pyc 		---<file>
|	|	|-PyAccess.cpython-39.pyc 		---<file>
|	|	|-SgiImagePlugin.cpython-39.pyc 		---<file>
|	|	|-SpiderImagePlugin.cpython-39.pyc 		---<file>
|	|	|-SunImagePlugin.cpython-39.pyc 		---<file>
|	|	|-TarIO.cpython-39.pyc 		---<file>
|	|	|-TgaImagePlugin.cpython-39.pyc 		---<file>
|	|	|-TiffImagePlugin.cpython-39.pyc 		---<file>
|	|	|-TiffTags.cpython-39.pyc 		---<file>
|	|	|-WalImageFile.cpython-39.pyc 		---<file>
|	|	|-WebPImagePlugin.cpython-39.pyc 		---<file>
|	|	|-WmfImagePlugin.cpython-39.pyc 		---<file>
|	|	|-XbmImagePlugin.cpython-39.pyc 		---<file>
|	|	|-XpmImagePlugin.cpython-39.pyc 		---<file>
|	|	|-XVThumbImagePlugin.cpython-39.pyc 		---<file>
|	|	|-_binary.cpython-39.pyc 		---<file>
|	|	|-_tkinter_finder.cpython-39.pyc 		---<file>
|	|	|-_util.cpython-39.pyc 		---<file>
|	|	|-_version.cpython-39.pyc 		---<file>
|	|	|-__init__.cpython-39.pyc 		---<file>
|	|	|-__main__.cpython-39.pyc 		---<file>

-4-Create- Create a new picture .

Be careful :

I believe you also found in the third quarter ,PIL It's just a folder , To quote it is to quote PIL In the catalog __init__.py, So input import PIL You can't .

---------

Method to create a picture :Image.new

Catalog

-MODE-

-SIZE-

-COLOR-


1】from PIL import Image

First of all, we need to use Image Library import .

2】img=Image.new(MODE,SIZE,COLOR)

Take another look at the official instructions 【 Source code 】:

def new(mode, size, color=0):
    """
    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.
    """

    _check_size(size)

    if color is None:
        # don't initialize
        return Image()._new(core.new(mode, size))

    if isinstance(color, str):
        # css3-style specifier

        from . import ImageColor

        color = ImageColor.getcolor(color, mode)

    im = Image()
    if mode == "P" and isinstance(color, (list, tuple)) and len(color) in [3, 4]:
        # RGB or RGBA value for a P image
        from . import ImagePalette

        im.palette = ImagePalette.ImagePalette()
        color = im.palette.getcolor(color)
    return im._new(core.fill(mode, size, color))

--------------------------------------------------------------------------------------------

-MODE-

  analysis :                         |___MODE: Pattern . Yes RGB( Three color combination , It's usually .jpg),

                                                RGBA( More transparency , Stored as .png Format ),

                                                1[ Bitmap (.bmp), Pixels 1 position ],

                                                L[ Grayscale , Pixels 8 position ],

                                                I[ Pixels Int32],

                                                F[ Pixels Float32],

                                                 P(PA)[8 position , Map pictures ]______

                                                CMYK[ printing ]                             |

                                                YCbCr[ Bright color separation ]                     |

                                                                                                |

                                About the mapping of images (P form ), to glance at :【Python】PIL Of images in the library mode Parameters _mjiansun The blog of -CSDN Blog

-SIZE-

requirement :tuple Array . otherwise :

ValueError: Size must be a tuple

example :(90,100)

It means the top is long 90 Pixels , high 100 Pixels .

-COLOR-

actually :

Image.new( mode, size ) => image
Image.new( mode, size, color ) => image

color As an additional parameter , Indicates fill color , If it is not filled in, it defaults to black .

Example of program :

from PIL import Image
img=Image.new("RGB",(100,100),"red")
img.show()

 

Watermarks are automatically added , There's No... on the computer  

-5- When you want to change the picture format 【 See above 】 when .

Image format : see -MODE

newimg=Image.convert(mode=None, matrix=None, dither=None, palette=WEB, colors=256)

Source code :

def convert(self, mode=None, matrix=None, dither=None, palette=WEB, colors=256):
    """
    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 128 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.
    """

    self.load()

    if not mode and self.mode == "P":
        # determine default mode
        if self.palette:
            mode = self.palette.mode
        else:
            mode = "RGB"
    if not mode or (mode == self.mode and not matrix):
        return self.copy()

    has_transparency = self.info.get("transparency") is not None
    if matrix:
        # matrix conversion
        if mode not in ("L", "RGB"):
            raise ValueError("illegal conversion")
        im = self.im.convert_matrix(mode, matrix)
        new = self._new(im)
        if has_transparency and self.im.bands == 3:
            transparency = new.info["transparency"]

            def convert_transparency(m, v):
                v = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3] * 0.5
                return max(0, min(255, int(v)))

            if mode == "L":
                transparency = convert_transparency(matrix, transparency)
            elif len(mode) == 3:
                transparency = tuple(
                    [
                        convert_transparency(
                            matrix[i * 4 : i * 4 + 4], transparency
                        )
                        for i in range(0, len(transparency))
                    ]
                )
            new.info["transparency"] = transparency
        return new

    if mode == "P" and self.mode == "RGBA":
        return self.quantize(colors)

    trns = None
    delete_trns = False
    # transparency handling
    if has_transparency:
        if self.mode in ("1", "L", "I", "RGB") and mode == "RGBA":
            # Use transparent conversion to promote from transparent
            # color to an alpha channel.
            new_im = self._new(
                self.im.convert_transparent(mode, self.info["transparency"])
            )
            del new_im.info["transparency"]
            return new_im
        elif self.mode in ("L", "RGB", "P") and mode in ("L", "RGB", "P"):
            t = self.info["transparency"]
            if isinstance(t, bytes):
                # Dragons. This can't be represented by a single color
                warnings.warn(
                    "Palette images with Transparency expressed in bytes should be "
                    "converted to RGBA images"
                )
                delete_trns = True
            else:
                # get the new transparency color.
                # use existing conversions
                trns_im = Image()._new(core.new(self.mode, (1, 1)))
                if self.mode == "P":
                    trns_im.putpalette(self.palette)
                    if isinstance(t, tuple):
                        try:
                            t = trns_im.palette.getcolor(t)
                        except Exception as e:
                            raise ValueError(
                                "Couldn't allocate a palette color for transparency"
                            ) from e
                trns_im.putpixel((0, 0), t)

                if mode in ("L", "RGB"):
                    trns_im = trns_im.convert(mode)
                else:
                    # can't just retrieve the palette number, got to do it
                    # after quantization.
                    trns_im = trns_im.convert("RGB")
                trns = trns_im.getpixel((0, 0))

        elif self.mode == "P" and mode == "RGBA":
            t = self.info["transparency"]
            delete_trns = True

            if isinstance(t, bytes):
                self.im.putpalettealphas(t)
            elif isinstance(t, int):
                self.im.putpalettealpha(t, 0)
            else:
                raise ValueError("Transparency for P mode should be bytes or int")

    if mode == "P" and palette == ADAPTIVE:
        im = self.im.quantize(colors)
        new = self._new(im)
        from . import ImagePalette

        new.palette = ImagePalette.raw("RGB", new.im.getpalette("RGB"))
        if delete_trns:
            # This could possibly happen if we requantize to fewer colors.
            # The transparency would be totally off in that case.
            del new.info["transparency"]
        if trns is not None:
            try:
                new.info["transparency"] = new.palette.getcolor(trns)
            except Exception:
                # if we can't make a transparent color, don't leave the old
                # transparency hanging around to mess us up.
                del new.info["transparency"]
                warnings.warn("Couldn't allocate palette entry for transparency")
        return new

    # colorspace conversion
    if dither is None:
        dither = FLOYDSTEINBERG

    try:
        im = self.im.convert(mode, dither)
    except ValueError:
        try:
            # normalize source image and try again
            im = self.im.convert(getmodebase(self.mode))
            im = im.convert(mode, dither)
        except KeyError as e:
            raise ValueError("illegal conversion") from e

    new_im = self._new(im)
    if delete_trns:
        # crash fail if we leave a bytes transparency in an rgb/l mode.
        del new_im.info["transparency"]
    if trns is not None:
        if new_im.mode == "P":
            try:
                new_im.info["transparency"] = new_im.palette.getcolor(trns)
            except Exception:
                del new_im.info["transparency"]
                warnings.warn("Couldn't allocate palette entry for transparency")
        else:
            new_im.info["transparency"] = trns
    return new_im

brief introduction :

( Machine translation - Translation from source code - brief introduction )

Returns a converted copy of this image . about “P” Pattern , this
    Method to convert pixels through the palette . If the mode is
    Omit , Select a mode , So that all the information in the image
    And the palette can be represented without a palette .

    The current version supports all possible transformations
    “L”、“RGB” and “CMYK”. ``matrix`` Parameters only support “L”
    and “RGB”.

    Convert color images to grayscale ( Pattern “L”) when ,
    The library uses ITU-R 601-2 Brightness conversion ::

        L = R * 299/1000 + G * 587/1000 + B * 114/1000

    Convert grayscale (“L”) or “RGB” The default method for
    Convert image to double layer ( Pattern “1”) Image use Floyd-Steinberg
    Dither to approximate the brightness level of the original image . If
    Jitter yes :data:`NONE`, All greater than 128 All the values of are set to 255( white ),
    All other values are 0( black ). To use other thresholds , Please use
    :py:meth:`~PIL.Image.Image.point` Method .

    In the absence of “ matrix ” Parameter from “RGBA” Convert to “P” when ,
    This passes the operation to :py:meth:`~PIL.Image.Image.quantize`,
    and ``dither`` and ``palette`` Be ignored .

    :param mode: The pattern of the request . See ::ref:`concept-modes`.
    :param matrix : Optional transformation matrix . If given , this
        It should contain floating-point values 4 or 12 Tuples .
    :param dither: Dithering method , Use... When converting from
        Pattern “RGB” To “P” Or from “RGB” or “L” To “1”.
        The available method is :data:`NONE` or :data:`FLOYDSTEINBERG`( Default ).
        Please note that , In providing ``matrix`` Do not use it .
    :param palette: Slave mode “RGB” The palette used in the conversion
        The best ”. The palette is available :data:`WEB` or :data:`ADAPTIVE`.
    :param Color : be used for :data:`ADAPTIVE` The number of colors in the palette .
        The default is 256.
    :rtype: :py:class:`~PIL.Image.Image`
    :returns: One :py:class:`~PIL.Image.Image` object .

----------------

Use

Don't be scared , Don't be frightened by it .

Generally speaking , When you open a picture 【 In the program 】, You may want to convert the format to make it easier to operate .

#img Is the open picture variable .
newimg=img.convert("RGBA")
# Of course , As long as it is the type mentioned before , Here's just an example .

The introduction also mentions , hold RGB Format conversion to L->

L = R * 299/1000 + G * 587/1000+ B * 114/1000 yes RGB To L Formula . 

  In general , That's enough .

If you want to know more ...

There is no more !【 Manual silence 】

Maybe you can only slowly find it on the foreign official website ...PILhttp://pythonware.com/products/pil/

 -6- When you want to open a picture

Image.open(path)

def open(fp, mode="r", formats=None):
    """
    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 ``python -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.
    """

Again , And don't be scared !!!


a=Image.open( route )

Means to load a picture , Then you can do it !

_________________________________

Image.open() In fact, it is equivalent to opening only one prefix , To load completely, wait until the actual operation .

Image.load() Can force load . 

原网站

版权声明
本文为[html_ finder]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111753277265.html