Plugin reference¶
AvifImagePlugin module¶
- class PIL.AvifImagePlugin.AvifImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile- load() Image.core.PixelAccess | None[source]¶
Load image data based on tile list
- seek(frame: int) None[source]¶
Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an
EOFErrorexception. When a sequence file is opened, the library automatically seeks to frame 0.See
tell().If defined,
n_framesrefers to the number of available frames.- Parameters:
frame – Frame number, starting at 0.
- Raises:
EOFError – If the call attempts to seek beyond the end of the sequence.
BmpImagePlugin module¶
- class PIL.BmpImagePlugin.BmpImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFileImage plugin for the Windows Bitmap format (BMP)
- BITFIELDS = 3¶
- COMPRESSIONS = {'BITFIELDS': 3, 'JPEG': 4, 'PNG': 5, 'RAW': 0, 'RLE4': 2, 'RLE8': 1}¶
- JPEG = 4¶
- PNG = 5¶
- RAW = 0¶
- RLE4 = 2¶
- RLE8 = 1¶
- k = 'PNG'¶
- v = 5¶
- class PIL.BmpImagePlugin.BmpRleDecoder(mode: str, *args: Any)[source]¶
Bases:
PyDecoder- decode(buffer: bytes | SupportsArrayInterface) tuple[int, int][source]¶
Override to perform the decoding process.
- Parameters:
buffer – A bytes object with the data to be decoded.
- Returns:
A tuple of
(bytes consumed, errcode). If finished with decoding return -1 for the bytes consumed. Err codes are fromImageFile.ERRORS.
BufrStubImagePlugin module¶
- class PIL.BufrStubImagePlugin.BufrStubImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
StubImageFile
- PIL.BufrStubImagePlugin.register_handler(handler: StubHandler | None) None[source]¶
Install application-specific BUFR image handler.
- Parameters:
handler – Handler object.
CurImagePlugin module¶
DcxImagePlugin module¶
- class PIL.DcxImagePlugin.DcxImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
PcxImageFile- seek(frame: int) None[source]¶
Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an
EOFErrorexception. When a sequence file is opened, the library automatically seeks to frame 0.See
tell().If defined,
n_framesrefers to the number of available frames.- Parameters:
frame – Frame number, starting at 0.
- Raises:
EOFError – If the call attempts to seek beyond the end of the sequence.
DdsImagePlugin module¶
A Pillow plugin for .dds files (S3TC-compressed aka DXTC) Jerome Leclanche <jerome@leclan.ch>
Documentation: https://web.archive.org/web/20170802060935/http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_compression_s3tc.txt
The contents of this file are hereby released in the public domain (CC0) Full text of the CC0 license: https://creativecommons.org/publicdomain/zero/1.0/
- class PIL.DdsImagePlugin.D3DFMT(*values)[source]¶
Bases:
IntEnum- A1 = 118¶
- A16B16G16R16 = 36¶
- A16B16G16R16F = 113¶
- A1R5G5B5 = 25¶
- A2B10G10R10 = 31¶
- A2B10G10R10_XR_BIAS = 119¶
- A2R10G10B10 = 35¶
- A2W10V10U10 = 67¶
- A32B32G32R32F = 116¶
- A4L4 = 52¶
- A4R4G4B4 = 26¶
- A8 = 28¶
- A8B8G8R8 = 32¶
- A8L8 = 51¶
- A8P8 = 40¶
- A8R3G3B2 = 29¶
- A8R8G8B8 = 21¶
- ATI1 = 826889281¶
- ATI2 = 843666497¶
- BC4S = 1395934018¶
- BC4U = 1429488450¶
- BC5S = 1395999554¶
- BC5U = 1429553986¶
- BINARYBUFFER = 199¶
- CxV8U8 = 117¶
- D15S1 = 73¶
- D16 = 80¶
- D16_LOCKABLE = 70¶
- D24FS8 = 83¶
- D24S8 = 75¶
- D24X4S4 = 79¶
- D24X8 = 77¶
- D32 = 71¶
- D32F_LOCKABLE = 82¶
- D32_LOCKABLE = 84¶
- DX10 = 808540228¶
- DXT1 = 827611204¶
- DXT2 = 844388420¶
- DXT3 = 861165636¶
- DXT4 = 877942852¶
- DXT5 = 894720068¶
- G16R16 = 34¶
- G16R16F = 112¶
- G32R32F = 115¶
- G8R8_G8B8 = 1111970375¶
- INDEX16 = 101¶
- INDEX32 = 102¶
- L16 = 81¶
- L6V5U5 = 61¶
- L8 = 50¶
- MULTI2_ARGB8 = 827606349¶
- P8 = 41¶
- Q16W16V16U16 = 110¶
- Q8W8V8U8 = 63¶
- R16F = 111¶
- R32F = 114¶
- R3G3B2 = 27¶
- R5G6B5 = 23¶
- R8G8B8 = 20¶
- R8G8_B8G8 = 1195525970¶
- S8_LOCKABLE = 85¶
- UNKNOWN = 0¶
- UYVY = 1498831189¶
- V16U16 = 64¶
- V8U8 = 60¶
- VERTEXDATA = 100¶
- X1R5G5B5 = 24¶
- X4R4G4B4 = 30¶
- X8B8G8R8 = 33¶
- X8L8V8U8 = 62¶
- X8R8G8B8 = 22¶
- YUY2 = 844715353¶
- class PIL.DdsImagePlugin.DDPF(*values)[source]¶
Bases:
IntFlag- ALPHA = 2¶
- ALPHAPIXELS = 1¶
- FOURCC = 4¶
- LUMINANCE = 131072¶
- PALETTEINDEXED8 = 32¶
- RGB = 64¶
- class PIL.DdsImagePlugin.DDSCAPS(*values)[source]¶
Bases:
IntFlag- COMPLEX = 8¶
- MIPMAP = 4194304¶
- TEXTURE = 4096¶
- class PIL.DdsImagePlugin.DDSCAPS2(*values)[source]¶
Bases:
IntFlag- CUBEMAP = 512¶
- CUBEMAP_NEGATIVEX = 2048¶
- CUBEMAP_NEGATIVEY = 8192¶
- CUBEMAP_NEGATIVEZ = 32768¶
- CUBEMAP_POSITIVEX = 1024¶
- CUBEMAP_POSITIVEY = 4096¶
- CUBEMAP_POSITIVEZ = 16384¶
- VOLUME = 2097152¶
- class PIL.DdsImagePlugin.DDSD(*values)[source]¶
Bases:
IntFlag- CAPS = 1¶
- DEPTH = 8388608¶
- HEIGHT = 2¶
- LINEARSIZE = 524288¶
- MIPMAPCOUNT = 131072¶
- PITCH = 8¶
- PIXELFORMAT = 4096¶
- WIDTH = 4¶
- class PIL.DdsImagePlugin.DXGI_FORMAT(*values)[source]¶
Bases:
IntEnum- A8P8 = 114¶
- A8_UNORM = 65¶
- AI44 = 111¶
- AYUV = 100¶
- B4G4R4A4_UNORM = 115¶
- B5G5R5A1_UNORM = 86¶
- B5G6R5_UNORM = 85¶
- B8G8R8A8_TYPELESS = 90¶
- B8G8R8A8_UNORM = 87¶
- B8G8R8A8_UNORM_SRGB = 91¶
- B8G8R8X8_TYPELESS = 92¶
- B8G8R8X8_UNORM = 88¶
- B8G8R8X8_UNORM_SRGB = 93¶
- BC1_TYPELESS = 70¶
- BC1_UNORM = 71¶
- BC1_UNORM_SRGB = 72¶
- BC2_TYPELESS = 73¶
- BC2_UNORM = 74¶
- BC2_UNORM_SRGB = 75¶
- BC3_TYPELESS = 76¶
- BC3_UNORM = 77¶
- BC3_UNORM_SRGB = 78¶
- BC4_SNORM = 81¶
- BC4_TYPELESS = 79¶
- BC4_UNORM = 80¶
- BC5_SNORM = 84¶
- BC5_TYPELESS = 82¶
- BC5_UNORM = 83¶
- BC6H_SF16 = 96¶
- BC6H_TYPELESS = 94¶
- BC6H_UF16 = 95¶
- BC7_TYPELESS = 97¶
- BC7_UNORM = 98¶
- BC7_UNORM_SRGB = 99¶
- D16_UNORM = 55¶
- D24_UNORM_S8_UINT = 45¶
- D32_FLOAT = 40¶
- D32_FLOAT_S8X24_UINT = 20¶
- G8R8_G8B8_UNORM = 69¶
- IA44 = 112¶
- NV11 = 110¶
- NV12 = 103¶
- OPAQUE_420 = 106¶
- P010 = 104¶
- P016 = 105¶
- P208 = 130¶
- P8 = 113¶
- R10G10B10A2_TYPELESS = 23¶
- R10G10B10A2_UINT = 25¶
- R10G10B10A2_UNORM = 24¶
- R10G10B10_XR_BIAS_A2_UNORM = 89¶
- R11G11B10_FLOAT = 26¶
- R16G16B16A16_FLOAT = 10¶
- R16G16B16A16_SINT = 14¶
- R16G16B16A16_SNORM = 13¶
- R16G16B16A16_TYPELESS = 9¶
- R16G16B16A16_UINT = 12¶
- R16G16B16A16_UNORM = 11¶
- R16G16_FLOAT = 34¶
- R16G16_SINT = 38¶
- R16G16_SNORM = 37¶
- R16G16_TYPELESS = 33¶
- R16G16_UINT = 36¶
- R16G16_UNORM = 35¶
- R16_FLOAT = 54¶
- R16_SINT = 59¶
- R16_SNORM = 58¶
- R16_TYPELESS = 53¶
- R16_UINT = 57¶
- R16_UNORM = 56¶
- R1_UNORM = 66¶
- R24G8_TYPELESS = 44¶
- R24_UNORM_X8_TYPELESS = 46¶
- R32G32B32A32_FLOAT = 2¶
- R32G32B32A32_SINT = 4¶
- R32G32B32A32_TYPELESS = 1¶
- R32G32B32A32_UINT = 3¶
- R32G32B32_FLOAT = 6¶
- R32G32B32_SINT = 8¶
- R32G32B32_TYPELESS = 5¶
- R32G32B32_UINT = 7¶
- R32G32_FLOAT = 16¶
- R32G32_SINT = 18¶
- R32G32_TYPELESS = 15¶
- R32G32_UINT = 17¶
- R32G8X24_TYPELESS = 19¶
- R32_FLOAT = 41¶
- R32_FLOAT_X8X24_TYPELESS = 21¶
- R32_SINT = 43¶
- R32_TYPELESS = 39¶
- R32_UINT = 42¶
- R8G8B8A8_SINT = 32¶
- R8G8B8A8_SNORM = 31¶
- R8G8B8A8_TYPELESS = 27¶
- R8G8B8A8_UINT = 30¶
- R8G8B8A8_UNORM = 28¶
- R8G8B8A8_UNORM_SRGB = 29¶
- R8G8_B8G8_UNORM = 68¶
- R8G8_SINT = 52¶
- R8G8_SNORM = 51¶
- R8G8_TYPELESS = 48¶
- R8G8_UINT = 50¶
- R8G8_UNORM = 49¶
- R8_SINT = 64¶
- R8_SNORM = 63¶
- R8_TYPELESS = 60¶
- R8_UINT = 62¶
- R8_UNORM = 61¶
- R9G9B9E5_SHAREDEXP = 67¶
- SAMPLER_FEEDBACK_MIN_MIP_OPAQUE = 189¶
- SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE = 190¶
- UNKNOWN = 0¶
- V208 = 131¶
- V408 = 132¶
- X24_TYPELESS_G8_UINT = 47¶
- X32_TYPELESS_G8X24_UINT = 22¶
- Y210 = 108¶
- Y216 = 109¶
- Y410 = 101¶
- Y416 = 102¶
- YUY2 = 107¶
- class PIL.DdsImagePlugin.DdsImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile
- class PIL.DdsImagePlugin.DdsRgbDecoder(mode: str, *args: Any)[source]¶
Bases:
PyDecoder- decode(buffer: bytes | SupportsArrayInterface) tuple[int, int][source]¶
Override to perform the decoding process.
- Parameters:
buffer – A bytes object with the data to be decoded.
- Returns:
A tuple of
(bytes consumed, errcode). If finished with decoding return -1 for the bytes consumed. Err codes are fromImageFile.ERRORS.
EpsImagePlugin module¶
- class PIL.EpsImagePlugin.EpsImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFileEPS File Parser for the Python Imaging Library
- load(scale: int = 1, transparency: bool = False) Image.core.PixelAccess | None[source]¶
Load image data based on tile list
- mode_map = {1: 'L', 2: 'LAB', 3: 'RGB', 4: 'CMYK'}¶
FitsImagePlugin module¶
- class PIL.FitsImagePlugin.FitsGzipDecoder(mode: str, *args: Any)[source]¶
Bases:
PyDecoder- decode(buffer: bytes | SupportsArrayInterface) tuple[int, int][source]¶
Override to perform the decoding process.
- Parameters:
buffer – A bytes object with the data to be decoded.
- Returns:
A tuple of
(bytes consumed, errcode). If finished with decoding return -1 for the bytes consumed. Err codes are fromImageFile.ERRORS.
FliImagePlugin module¶
- class PIL.FliImagePlugin.FliImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile- seek(frame: int) None[source]¶
Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an
EOFErrorexception. When a sequence file is opened, the library automatically seeks to frame 0.See
tell().If defined,
n_framesrefers to the number of available frames.- Parameters:
frame – Frame number, starting at 0.
- Raises:
EOFError – If the call attempts to seek beyond the end of the sequence.
FpxImagePlugin module¶
- class PIL.FpxImagePlugin.FpxImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile- close() None[source]¶
Closes the file pointer, if possible.
This operation will destroy the image core and release its memory. The image data will be unusable afterward.
This function is required to close images that have multiple frames or have not had their file read and closed by the
load()method. See File handling in Pillow for more information.
- load() Image.core.PixelAccess | None[source]¶
Load image data based on tile list
GbrImagePlugin module¶
GifImagePlugin module¶
- class PIL.GifImagePlugin.GifImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile- global_palette = None¶
- seek(frame: int) None[source]¶
Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an
EOFErrorexception. When a sequence file is opened, the library automatically seeks to frame 0.See
tell().If defined,
n_framesrefers to the number of available frames.- Parameters:
frame – Frame number, starting at 0.
- Raises:
EOFError – If the call attempts to seek beyond the end of the sequence.
- PIL.GifImagePlugin.LOADING_STRATEGY = LoadingStrategy.RGB_AFTER_FIRST¶
Added in version 9.1.0.
- class PIL.GifImagePlugin.LoadingStrategy(*values)[source]¶
Bases:
IntEnumAdded in version 9.1.0.
- RGB_AFTER_DIFFERENT_PALETTE_ONLY = 1¶
- RGB_AFTER_FIRST = 0¶
- RGB_ALWAYS = 2¶
- PIL.GifImagePlugin.getdata(im: Image, offset: tuple[int, int] = (0, 0), **params: Any) list[bytes][source]¶
Legacy Method
Return a list of strings representing this image. The first string is a local image header, the rest contains encoded image data.
To specify duration, add the time in milliseconds, e.g.
getdata(im_frame, duration=1000)- Parameters:
im – Image object
offset – Tuple of (x, y) pixels. Defaults to (0, 0)
**params – e.g. duration or other encoder info parameters
- Returns:
List of bytes containing GIF encoded frame data
- PIL.GifImagePlugin.getheader(im: Image, palette: bytes | bytearray | list[int] | ImagePalette | None = None, info: dict[str, Any] | None = None) tuple[list[bytes], list[int] | None][source]¶
Legacy Method to get Gif data from image.
Warning:: May modify image data.
- Parameters:
im – Image object
palette – bytes object containing the source palette, or ….
info – encoderinfo
- Returns:
tuple of(list of header items, optimized palette)
GribStubImagePlugin module¶
- class PIL.GribStubImagePlugin.GribStubImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
StubImageFile
- PIL.GribStubImagePlugin.register_handler(handler: StubHandler | None) None[source]¶
Install application-specific GRIB image handler.
- Parameters:
handler – Handler object.
Hdf5StubImagePlugin module¶
- class PIL.Hdf5StubImagePlugin.HDF5StubImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
StubImageFile
- PIL.Hdf5StubImagePlugin.register_handler(handler: StubHandler | None) None[source]¶
Install application-specific HDF5 image handler.
- Parameters:
handler – Handler object.
IcnsImagePlugin module¶
- class PIL.IcnsImagePlugin.IcnsFile(fobj: IO[bytes])[source]¶
Bases:
object- SIZES = {(16, 16, 1): [(b'icp4', <function read_png_or_jpeg2000>), (b'is32', <function read_32>), (b's8mk', <function read_mk>)], (16, 16, 2): [(b'ic11', <function read_png_or_jpeg2000>)], (32, 32, 1): [(b'icp5', <function read_png_or_jpeg2000>), (b'il32', <function read_32>), (b'l8mk', <function read_mk>)], (32, 32, 2): [(b'ic12', <function read_png_or_jpeg2000>)], (48, 48, 1): [(b'ih32', <function read_32>), (b'h8mk', <function read_mk>)], (64, 64, 1): [(b'icp6', <function read_png_or_jpeg2000>)], (128, 128, 1): [(b'ic07', <function read_png_or_jpeg2000>), (b'it32', <function read_32t>), (b't8mk', <function read_mk>)], (128, 128, 2): [(b'ic13', <function read_png_or_jpeg2000>)], (256, 256, 1): [(b'ic08', <function read_png_or_jpeg2000>)], (256, 256, 2): [(b'ic14', <function read_png_or_jpeg2000>)], (512, 512, 1): [(b'ic09', <function read_png_or_jpeg2000>)], (512, 512, 2): [(b'ic10', <function read_png_or_jpeg2000>)]}¶
- class PIL.IcnsImagePlugin.IcnsImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFilePIL image support for Mac OS .icns files. Chooses the best resolution, but will possibly load a different size image if you mutate the size attribute before calling ‘load’.
The info dictionary has a key ‘sizes’ that is a list of sizes that the icns file has.
- PIL.IcnsImagePlugin.read_32(fobj: IO[bytes], start_length: tuple[int, int], size: tuple[int, int, int]) dict[str, Image][source]¶
Read a 32bit RGB icon resource. Seems to be either uncompressed or an RLE packbits-like scheme.
- PIL.IcnsImagePlugin.read_32t(fobj: IO[bytes], start_length: tuple[int, int], size: tuple[int, int, int]) dict[str, Image][source]¶
IcoImagePlugin module¶
- class PIL.IcoImagePlugin.IcoImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFilePIL read-only image support for Microsoft Windows .ico files.
By default the largest resolution image in the file will be loaded. This can be changed by altering the ‘size’ attribute before calling ‘load’.
The info dictionary has a key ‘sizes’ that is a list of the sizes available in the icon file.
Handles classic, XP and Vista icon formats.
When saving, PNG compression is used. Support for this was only added in Windows Vista. If you are unable to view the icon in Windows, convert the image to “RGBA” mode before saving.
This plugin is a refactored version of Win32IconImagePlugin by Bryan Davis <casadebender@gmail.com>. https://code.google.com/archive/p/casadebender/wikis/Win32IconImagePlugin.wiki
- load() Image.core.PixelAccess | None[source]¶
Load image data based on tile list
- class PIL.IcoImagePlugin.IconHeader(width, height, nb_color, reserved, planes, bpp, size, offset, dim, square, color_depth)[source]¶
Bases:
NamedTuple
ImImagePlugin module¶
- class PIL.ImImagePlugin.ImImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile- seek(frame: int) None[source]¶
Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an
EOFErrorexception. When a sequence file is opened, the library automatically seeks to frame 0.See
tell().If defined,
n_framesrefers to the number of available frames.- Parameters:
frame – Frame number, starting at 0.
- Raises:
EOFError – If the call attempts to seek beyond the end of the sequence.
ImtImagePlugin module¶
IptcImagePlugin module¶
- class PIL.IptcImagePlugin.IptcImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile- load() Image.core.PixelAccess | None[source]¶
Load image data based on tile list
- PIL.IptcImagePlugin.getiptcinfo(im: ImageFile) dict[tuple[int, int], bytes | list[bytes]] | None[source]¶
Get IPTC information from TIFF, JPEG, or IPTC file.
- Parameters:
im – An image containing IPTC data.
- Returns:
A dictionary containing IPTC information, or None if no IPTC information block was found.
JpegImagePlugin module¶
- PIL.JpegImagePlugin.APP(self: JpegImageFile, marker: int) None[source]¶
- PIL.JpegImagePlugin.COM(self: JpegImageFile, marker: int) None[source]¶
- PIL.JpegImagePlugin.DQT(self: JpegImageFile, marker: int) None[source]¶
- class PIL.JpegImagePlugin.JpegImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile- draft(mode: str | None, size: tuple[int, int] | None) tuple[str, tuple[int, int, float, float]] | None[source]¶
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
modeandboxwith coordinates of the original image within the altered one.Note that this method modifies the
Imageobject 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.
- Parameters:
mode – The requested mode.
size – The requested size in pixels, as a 2-tuple: (width, height).
- PIL.JpegImagePlugin.SOF(self: JpegImageFile, marker: int) None[source]¶
- PIL.JpegImagePlugin.Skip(self: JpegImageFile, marker: int) None[source]¶
- PIL.JpegImagePlugin.jpeg_factory(fp: IO[bytes], filename: str | bytes | None = None) JpegImageFile | MpoImageFile[source]¶
Jpeg2KImagePlugin module¶
- class PIL.Jpeg2KImagePlugin.BoxReader(fp: IO[bytes], length: int = -1)[source]¶
Bases:
objectA small helper class to read fields stored in JPEG2000 header boxes and to easily step into and read sub-boxes.
- class PIL.Jpeg2KImagePlugin.Jpeg2KImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile- load() Image.core.PixelAccess | None[source]¶
Load image data based on tile list
- property reduce: Callable[[int | tuple[int, int], tuple[int, int, int, int] | None], Image.Image] | int¶
Returns a copy of the image reduced
factortimes. If the size of the image is not dividable byfactor, the resulting size will be rounded up.- Parameters:
factor – A greater than 0 integer or tuple of two integers for width and height separately.
box – An optional 4-tuple of ints providing the source image region to be reduced. The values must be within
(0, 0, width, height)rectangle. If omitted orNone, the entire source is used.
McIdasImagePlugin module¶
MicImagePlugin module¶
- class PIL.MicImagePlugin.MicImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
TiffImageFile- close() None[source]¶
Closes the file pointer, if possible.
This operation will destroy the image core and release its memory. The image data will be unusable afterward.
This function is required to close images that have multiple frames or have not had their file read and closed by the
load()method. See File handling in Pillow for more information.
MpegImagePlugin module¶
- class PIL.MpegImagePlugin.BitStream(fp: SupportsRead[bytes])[source]¶
Bases:
object
MpoImagePlugin module¶
- class PIL.MpoImagePlugin.MpoImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
JpegImageFile- static adopt(jpeg_instance: JpegImageFile, mpheader: dict[int, Any] | None = None) MpoImageFile[source]¶
Transform the instance of JpegImageFile into an instance of MpoImageFile. After the call, the JpegImageFile is extended to be an MpoImageFile.
This is essentially useful when opening a JPEG file that reveals itself as an MPO, to avoid double call to _open.
- seek(frame: int) None[source]¶
Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an
EOFErrorexception. When a sequence file is opened, the library automatically seeks to frame 0.See
tell().If defined,
n_framesrefers to the number of available frames.- Parameters:
frame – Frame number, starting at 0.
- Raises:
EOFError – If the call attempts to seek beyond the end of the sequence.
MspImagePlugin module¶
- class PIL.MspImagePlugin.MspDecoder(mode: str, *args: Any)[source]¶
Bases:
PyDecoder- decode(buffer: bytes | SupportsArrayInterface) tuple[int, int][source]¶
Override to perform the decoding process.
- Parameters:
buffer – A bytes object with the data to be decoded.
- Returns:
A tuple of
(bytes consumed, errcode). If finished with decoding return -1 for the bytes consumed. Err codes are fromImageFile.ERRORS.
PalmImagePlugin module¶
PcdImagePlugin module¶
PcxImagePlugin module¶
PdfImagePlugin module¶
PixarImagePlugin module¶
PngImagePlugin module¶
- class PIL.PngImagePlugin.Blend(*values)[source]¶
Bases:
IntEnum- OP_OVER = 1¶
This frame should be alpha composited with the previous output image contents. See Saving APNG sequences.
- OP_SOURCE = 0¶
All color components of this frame, including alpha, overwrite the previous output image contents. See Saving APNG sequences.
- class PIL.PngImagePlugin.Disposal(*values)[source]¶
Bases:
IntEnum- OP_BACKGROUND = 1¶
This frame’s modified region is cleared to fully transparent black before rendering the next frame. See Saving APNG sequences.
- OP_NONE = 0¶
No disposal is done on this frame before rendering the next frame. See Saving APNG sequences.
- OP_PREVIOUS = 2¶
This frame’s modified region is reverted to the previous frame’s contents before rendering the next frame. See Saving APNG sequences.
- class PIL.PngImagePlugin.PngImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile- seek(frame: int) None[source]¶
Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an
EOFErrorexception. When a sequence file is opened, the library automatically seeks to frame 0.See
tell().If defined,
n_framesrefers to the number of available frames.- Parameters:
frame – Frame number, starting at 0.
- Raises:
EOFError – If the call attempts to seek beyond the end of the sequence.
- class PIL.PngImagePlugin.PngStream(fp: IO[bytes])[source]¶
Bases:
ChunkStream
- PIL.PngImagePlugin.getchunks(im: Image.Image, **params: Any) list[tuple[bytes, bytes, bytes]][source]¶
Return a list of PNG chunks representing this image.
- PIL.PngImagePlugin.is_cid(string, pos=0, endpos=9223372036854775807)¶
Matches zero or more characters at the beginning of the string.
- PIL.PngImagePlugin.putchunk(fp: IO[bytes], cid: bytes, *data: bytes) None[source]¶
Write a PNG chunk (including CRC field)
- PIL.PngImagePlugin.MAX_TEXT_CHUNK = 1048576¶
Maximum decompressed size for a iTXt or zTXt chunk. Eliminates decompression bombs where compressed chunks can expand 1000x. See Text in PNG File Format.
- PIL.PngImagePlugin.MAX_TEXT_MEMORY = 67108864¶
Set the maximum total text chunk size. See Text in PNG File Format.
PpmImagePlugin module¶
- class PIL.PpmImagePlugin.PpmDecoder(mode: str, *args: Any)[source]¶
Bases:
PyDecoder- decode(buffer: bytes | SupportsArrayInterface) tuple[int, int][source]¶
Override to perform the decoding process.
- Parameters:
buffer – A bytes object with the data to be decoded.
- Returns:
A tuple of
(bytes consumed, errcode). If finished with decoding return -1 for the bytes consumed. Err codes are fromImageFile.ERRORS.
- class PIL.PpmImagePlugin.PpmImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile
- class PIL.PpmImagePlugin.PpmPlainDecoder(mode: str, *args: Any)[source]¶
Bases:
PyDecoder- decode(buffer: bytes | SupportsArrayInterface) tuple[int, int][source]¶
Override to perform the decoding process.
- Parameters:
buffer – A bytes object with the data to be decoded.
- Returns:
A tuple of
(bytes consumed, errcode). If finished with decoding return -1 for the bytes consumed. Err codes are fromImageFile.ERRORS.
PsdImagePlugin module¶
- class PIL.PsdImagePlugin.PsdImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile- seek(layer: int) None[source]¶
Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an
EOFErrorexception. When a sequence file is opened, the library automatically seeks to frame 0.See
tell().If defined,
n_framesrefers to the number of available frames.- Parameters:
frame – Frame number, starting at 0.
- Raises:
EOFError – If the call attempts to seek beyond the end of the sequence.
SgiImagePlugin module¶
- class PIL.SgiImagePlugin.SGI16Decoder(mode: str, *args: Any)[source]¶
Bases:
PyDecoder- decode(buffer: bytes | SupportsArrayInterface) tuple[int, int][source]¶
Override to perform the decoding process.
- Parameters:
buffer – A bytes object with the data to be decoded.
- Returns:
A tuple of
(bytes consumed, errcode). If finished with decoding return -1 for the bytes consumed. Err codes are fromImageFile.ERRORS.
SpiderImagePlugin module¶
- class PIL.SpiderImagePlugin.SpiderImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile- seek(frame: int) None[source]¶
Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an
EOFErrorexception. When a sequence file is opened, the library automatically seeks to frame 0.See
tell().If defined,
n_framesrefers to the number of available frames.- Parameters:
frame – Frame number, starting at 0.
- Raises:
EOFError – If the call attempts to seek beyond the end of the sequence.
- tell() int[source]¶
Returns the current frame number. See
seek().If defined,
n_framesrefers to the number of available frames.- Returns:
Frame number, starting with 0.
- tkPhotoImage() ImageTk.PhotoImage[source]¶
SunImagePlugin module¶
TgaImagePlugin module¶
TiffImagePlugin module¶
- class PIL.TiffImagePlugin.AppendingTiffWriter(fn: StrOrBytesPath | IO[bytes], new: bool = False)[source]¶
Bases:
BytesIO- Tags = {273, 288, 324, 519, 520, 521}¶
- fieldSizes = [0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4, 2, 4, 8]¶
- class PIL.TiffImagePlugin.IFDRational(value: float | Fraction | IFDRational, denominator: int = 1)[source]¶
Bases:
RationalImplements a rational class where 0/0 is a legal value to match the in the wild use of exif rationals.
e.g., DigitalZoomRatio - 0.00/0.00 indicates that no digital zoom was used
- limit_rational(max_denominator: int) tuple[IntegralLike, int][source]¶
- Parameters:
max_denominator – Integer, the maximum denominator value
- Returns:
Tuple of (numerator, denominator)
- property numerator: IntegralLike¶
- PIL.TiffImagePlugin.ImageFileDirectory¶
alias of
ImageFileDirectory_v1
- class PIL.TiffImagePlugin.ImageFileDirectory_v1(*args: Any, **kwargs: Any)[source]¶
Bases:
ImageFileDirectory_v2This class represents the legacy interface to a TIFF tag directory.
Exposes a dictionary interface of the tags in the directory:
ifd = ImageFileDirectory_v1() ifd[key] = 'Some Data' ifd.tagtype[key] = TiffTags.ASCII print(ifd[key]) ('Some Data',)
Also contains a dictionary of tag types as read from the tiff image file,
tagtype.Values are returned as a tuple.
Deprecated since version 3.0.0.
- classmethod from_v2(original: ImageFileDirectory_v2) ImageFileDirectory_v1[source]¶
Returns an
ImageFileDirectory_v1instance with the same data as is contained in the originalImageFileDirectory_v2instance.- Returns:
- property tagdata¶
- property tags¶
- to_v2() ImageFileDirectory_v2[source]¶
Returns an
ImageFileDirectory_v2instance with the same data as is contained in the originalImageFileDirectory_v1instance.- Returns:
- class PIL.TiffImagePlugin.ImageFileDirectory_v2(ifh: bytes = b'II*\x00\x00\x00\x00\x00', prefix: bytes | None = None, group: int | None = None)[source]¶
Bases:
MutableMappingThis class represents a TIFF tag directory. To speed things up, we don’t decode tags unless they’re asked for.
Exposes a dictionary interface of the tags in the directory:
ifd = ImageFileDirectory_v2() ifd[key] = 'Some Data' ifd.tagtype[key] = TiffTags.ASCII print(ifd[key]) 'Some Data'
Individual values are returned as the strings or numbers, sequences are returned as tuples of the values.
The tiff metadata type of each item is stored in a dictionary of tag types in
tagtype. The types are read from a tiff file, guessed from the type added, or added manually.Data Structures:
self.tagtype = {}Key: numerical TIFF tag number
Value: integer corresponding to the data type from
TiffTags.TYPES
Added in version 3.0.0.
‘Internal’ data structures:
self._tags_v2 = {}Key: numerical TIFF tag number
Value: decoded data, as tuple for multiple values
self._tagdata = {}Key: numerical TIFF tag number
Value: undecoded byte string from file
self._tags_v1 = {}Key: numerical TIFF tag number
Value: decoded data in the v1 format
Tags will be found in the private attributes
self._tagdata, and inself._tags_v2once decoded.self.legacy_apiis a value for internal use, and shouldn’t be changed from outside code. In cooperation withImageFileDirectory_v1, iflegacy_apiis true, then decoded tags will be populated into both_tags_v1and_tags_v2._tags_v2will be used if this IFD is used in the TIFF save routine. Tags should be read from_tags_v1iflegacy_api == true.- load_rational(data: bytes, legacy_api: bool = True) tuple[tuple[int, int] | IFDRational, ...][source]¶
- load_signed_rational(data: bytes, legacy_api: bool = True) tuple[tuple[int, int] | IFDRational, ...][source]¶
- named() dict[str, Any][source]¶
- Returns:
dict of name|key: value
Returns the complete tag dictionary, with named tags where possible.
- property offset¶
- property prefix¶
- write_double(*values)¶
- write_float(*values)¶
- write_long(*values)¶
- write_long8(*values)¶
- write_rational(*values: IFDRational) bytes[source]¶
- write_short(*values)¶
- write_signed_byte(*values)¶
- write_signed_long(*values)¶
- write_signed_rational(*values: IFDRational) bytes[source]¶
- write_signed_short(*values)¶
- class PIL.TiffImagePlugin.TiffImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile- get_photoshop_blocks() dict[int, dict[str, bytes]][source]¶
Returns a dictionary of Photoshop “Image Resource Blocks”. The keys are the image resource ID. For more information, see https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577409_pgfId-1037727
- Returns:
Photoshop “Image Resource Blocks” in a dictionary.
- load() Image.core.PixelAccess | None[source]¶
Load image data based on tile list
- tag: ImageFileDirectory_v1¶
Legacy tag entries
- tag_v2: ImageFileDirectory_v2¶
Image file directory (tag dictionary)
WebPImagePlugin module¶
- class PIL.WebPImagePlugin.WebPImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
ImageFile- load() Image.core.PixelAccess | None[source]¶
Load image data based on tile list
- seek(frame: int) None[source]¶
Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an
EOFErrorexception. When a sequence file is opened, the library automatically seeks to frame 0.See
tell().If defined,
n_framesrefers to the number of available frames.- Parameters:
frame – Frame number, starting at 0.
- Raises:
EOFError – If the call attempts to seek beyond the end of the sequence.
WmfImagePlugin module¶
- class PIL.WmfImagePlugin.WmfStubImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[source]¶
Bases:
StubImageFile
- PIL.WmfImagePlugin.register_handler(handler: StubHandler | None) None[source]¶
Install application-specific WMF image handler.
- Parameters:
handler – Handler object.
XVThumbImagePlugin module¶
XbmImagePlugin module¶
XpmImagePlugin module¶
- class PIL.XpmImagePlugin.XpmDecoder(mode: str, *args: Any)[source]¶
Bases:
PyDecoder- decode(buffer: bytes | SupportsArrayInterface) tuple[int, int][source]¶
Override to perform the decoding process.
- Parameters:
buffer – A bytes object with the data to be decoded.
- Returns:
A tuple of
(bytes consumed, errcode). If finished with decoding return -1 for the bytes consumed. Err codes are fromImageFile.ERRORS.