Plugin reference#

BmpImagePlugin Module#

class PIL.BmpImagePlugin.BmpImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

Image 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#
format: str | None = 'BMP'#
format_description: str | None = 'Windows Bitmap'#
k = 'PNG'#
v = 5#
class PIL.BmpImagePlugin.BmpRleDecoder(mode, *args)[source]#

Bases: PyDecoder

decode(buffer)[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 from ImageFile.ERRORS.

class PIL.BmpImagePlugin.DibImageFile(fp=None, filename=None)[source]#

Bases: BmpImageFile

format: str | None = 'DIB'#
format_description: str | None = 'Windows Bitmap'#

BufrStubImagePlugin Module#

class PIL.BufrStubImagePlugin.BufrStubImageFile(fp=None, filename=None)[source]#

Bases: StubImageFile

format: str | None = 'BUFR'#
format_description: str | None = 'BUFR'#
PIL.BufrStubImagePlugin.register_handler(handler)[source]#

Install application-specific BUFR image handler.

Parameters:

handler – Handler object.

CurImagePlugin Module#

class PIL.CurImagePlugin.CurImageFile(fp=None, filename=None)[source]#

Bases: BmpImageFile

format: str | None = 'CUR'#
format_description: str | None = 'Windows Cursor'#

DcxImagePlugin Module#

class PIL.DcxImagePlugin.DcxImageFile(fp=None, filename=None)[source]#

Bases: PcxImageFile

format: str | None = 'DCX'#
format_description: str | None = 'Intel DCX'#
seek(frame)[source]#

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 tell().

If defined, n_frames refers 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()[source]#

Returns the current frame number. See seek().

If defined, n_frames refers to the number of available frames.

Returns:

Frame number, starting with 0.

DdsImagePlugin Module#

A Pillow loader 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(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[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(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: IntFlag

ALPHA = 2#
ALPHAPIXELS = 1#
FOURCC = 4#
LUMINANCE = 131072#
PALETTEINDEXED8 = 32#
RGB = 64#
class PIL.DdsImagePlugin.DDSCAPS(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: IntFlag

COMPLEX = 8#
MIPMAP = 4194304#
TEXTURE = 4096#
class PIL.DdsImagePlugin.DDSCAPS2(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[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(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: IntFlag

CAPS = 1#
DEPTH = 8388608#
HEIGHT = 2#
LINEARSIZE = 524288#
MIPMAPCOUNT = 131072#
PITCH = 8#
PIXELFORMAT = 4096#
WIDTH = 4#
class PIL.DdsImagePlugin.DXGI_FORMAT(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[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=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'DDS'#
format_description: str | None = 'DirectDraw Surface'#
load_seek(pos)[source]#
class PIL.DdsImagePlugin.DdsRgbDecoder(mode, *args)[source]#

Bases: PyDecoder

decode(buffer)[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 from ImageFile.ERRORS.

EpsImagePlugin Module#

class PIL.EpsImagePlugin.EpsImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

EPS File Parser for the Python Imaging Library

format: str | None = 'EPS'#
format_description: str | None = 'Encapsulated Postscript'#
load(scale=1, transparency=False)[source]#

Load image data based on tile list

load_seek(*args, **kwargs)[source]#
mode_map = {1: 'L', 2: 'LAB', 3: 'RGB', 4: 'CMYK'}#
PIL.EpsImagePlugin.Ghostscript(tile, size, fp, scale=1, transparency=False)[source]#

Render an image using Ghostscript

class PIL.EpsImagePlugin.PSFile(fp)[source]#

Bases: object

Wrapper for bytesio object that treats either CR or LF as end of line. This class is no longer used internally, but kept for backwards compatibility.

readline()[source]#
seek(offset, whence=0)[source]#
PIL.EpsImagePlugin.has_ghostscript()[source]#

FitsImagePlugin Module#

class PIL.FitsImagePlugin.FitsImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'FITS'#
format_description: str | None = 'FITS'#

FliImagePlugin Module#

class PIL.FliImagePlugin.FliImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'FLI'#
format_description: str | None = 'Autodesk FLI/FLC Animation'#
seek(frame)[source]#

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 tell().

If defined, n_frames refers 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()[source]#

Returns the current frame number. See seek().

If defined, n_frames refers to the number of available frames.

Returns:

Frame number, starting with 0.

FpxImagePlugin Module#

class PIL.FpxImagePlugin.FpxImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

close()[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.

format: str | None = 'FPX'#
format_description: str | None = 'FlashPix'#
load()[source]#

Load image data based on tile list

GbrImagePlugin Module#

class PIL.GbrImagePlugin.GbrImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'GBR'#
format_description: str | None = 'GIMP brush file'#
load()[source]#

Load image data based on tile list

GifImagePlugin Module#

class PIL.GifImagePlugin.GifImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

data()[source]#
format: str | None = 'GIF'#
format_description: str | None = 'Compuserve GIF'#
global_palette = None#
property is_animated#
load_end()[source]#
load_prepare()[source]#
property n_frames#
seek(frame)[source]#

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 tell().

If defined, n_frames refers 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()[source]#

Returns the current frame number. See seek().

If defined, n_frames refers to the number of available frames.

Returns:

Frame number, starting with 0.

PIL.GifImagePlugin.LOADING_STRATEGY = LoadingStrategy.RGB_AFTER_FIRST#

New in version 9.1.0.

class PIL.GifImagePlugin.LoadingStrategy(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: IntEnum

New in version 9.1.0.

RGB_AFTER_DIFFERENT_PALETTE_ONLY = 1#
RGB_AFTER_FIRST = 0#
RGB_ALWAYS = 2#
PIL.GifImagePlugin.get_interlace(im)[source]#
PIL.GifImagePlugin.getdata(im, offset=(0, 0), **params)[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, palette=None, info=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=None, filename=None)[source]#

Bases: StubImageFile

format: str | None = 'GRIB'#
format_description: str | None = 'GRIB'#
PIL.GribStubImagePlugin.register_handler(handler)[source]#

Install application-specific GRIB image handler.

Parameters:

handler – Handler object.

Hdf5StubImagePlugin Module#

class PIL.Hdf5StubImagePlugin.HDF5StubImageFile(fp=None, filename=None)[source]#

Bases: StubImageFile

format: str | None = 'HDF5'#
format_description: str | None = 'HDF5'#
PIL.Hdf5StubImagePlugin.register_handler(handler)[source]#

Install application-specific HDF5 image handler.

Parameters:

handler – Handler object.

IcnsImagePlugin Module#

class PIL.IcnsImagePlugin.IcnsFile(fobj)[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>)]}#
bestsize()[source]#
dataforsize(size)[source]#

Get an icon resource as {channel: array}. Note that the arrays are bottom-up like windows bitmaps and will likely need to be flipped or transposed in some way.

getimage(size=None)[source]#
itersizes()[source]#
class PIL.IcnsImagePlugin.IcnsImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

PIL 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.

format: str | None = 'ICNS'#
format_description: str | None = 'Mac OS icns resource'#
load()[source]#

Load image data based on tile list

property size#
PIL.IcnsImagePlugin.nextheader(fobj)[source]#
PIL.IcnsImagePlugin.read_32(fobj, start_length, size)[source]#

Read a 32bit RGB icon resource. Seems to be either uncompressed or an RLE packbits-like scheme.

PIL.IcnsImagePlugin.read_32t(fobj, start_length, size)[source]#
PIL.IcnsImagePlugin.read_mk(fobj, start_length, size)[source]#
PIL.IcnsImagePlugin.read_png_or_jpeg2000(fobj, start_length, size)[source]#

IcoImagePlugin Module#

class PIL.IcoImagePlugin.IcoFile(buf)[source]#

Bases: object

frame(idx)[source]#

Get an image from frame idx

getentryindex(size, bpp=False)[source]#
getimage(size, bpp=False)[source]#

Get an image from the icon

sizes()[source]#

Get a list of all available icon sizes and color depths.

class PIL.IcoImagePlugin.IcoImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

PIL 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

format: str | None = 'ICO'#
format_description: str | None = 'Windows Icon'#
load()[source]#

Load image data based on tile list

load_seek()[source]#
property size#

ImImagePlugin Module#

class PIL.ImImagePlugin.ImImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'IM'#
format_description: str | None = 'IFUNC Image Memory'#
property is_animated#
property n_frames#
seek(frame)[source]#

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 tell().

If defined, n_frames refers 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()[source]#

Returns the current frame number. See seek().

If defined, n_frames refers to the number of available frames.

Returns:

Frame number, starting with 0.

PIL.ImImagePlugin.number(s)[source]#

ImtImagePlugin Module#

class PIL.ImtImagePlugin.ImtImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'IMT'#
format_description: str | None = 'IM Tools'#

IptcImagePlugin Module#

class PIL.IptcImagePlugin.IptcImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

field() tuple[tuple[int, int] | None, int][source]#
format: str | None = 'IPTC'#
format_description: str | None = 'IPTC/NAA'#
getint(key: tuple[int, int]) int[source]#
load()[source]#

Load image data based on tile list

PIL.IptcImagePlugin.dump(c: Sequence[int | bytes]) None[source]#

Deprecated since version 10.2.0.

PIL.IptcImagePlugin.getiptcinfo(im)[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.

PIL.IptcImagePlugin.i(c: bytes) int[source]#

Deprecated since version 10.2.0.

JpegImagePlugin Module#

PIL.JpegImagePlugin.APP(self, marker)[source]#
PIL.JpegImagePlugin.COM(self, marker)[source]#
PIL.JpegImagePlugin.DQT(self, marker)[source]#
class PIL.JpegImagePlugin.JpegImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

draft(mode, size)[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 mode and box with coordinates of the original image within the altered one.

Note that this method modifies the 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.

Parameters:
  • mode – The requested mode.

  • size – The requested size in pixels, as a 2-tuple: (width, height).

format: str | None = 'JPEG'#
format_description: str | None = 'JPEG (ISO 10918)'#
getxmp()[source]#

Returns a dictionary containing the XMP tags. Requires defusedxml to be installed.

Returns:

XMP tags in a dictionary.

load_djpeg()[source]#
load_read(read_bytes)[source]#

internal: read more image data For premature EOF and LOAD_TRUNCATED_IMAGES adds EOI marker so libjpeg can finish decoding

PIL.JpegImagePlugin.SOF(self, marker)[source]#
PIL.JpegImagePlugin.Skip(self, marker)[source]#
PIL.JpegImagePlugin.get_sampling(im)[source]#
PIL.JpegImagePlugin.jpeg_factory(fp=None, filename=None)[source]#

Jpeg2KImagePlugin Module#

class PIL.Jpeg2KImagePlugin.BoxReader(fp, length=-1)[source]#

Bases: object

A small helper class to read fields stored in JPEG2000 header boxes and to easily step into and read sub-boxes.

has_next_box()[source]#
next_box_type()[source]#
read_boxes()[source]#
read_fields(field_format)[source]#
class PIL.Jpeg2KImagePlugin.Jpeg2KImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'JPEG2000'#
format_description: str | None = 'JPEG 2000 (ISO 15444)'#
load()[source]#

Load image data based on tile list

property reduce#

Returns a copy of the image reduced factor times. If the size of the image is not dividable by factor, the resulting size will be rounded up.

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 or None, the entire source is used.

McIdasImagePlugin Module#

class PIL.McIdasImagePlugin.McIdasImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'MCIDAS'#
format_description: str | None = 'McIdas area file'#

MicImagePlugin Module#

class PIL.MicImagePlugin.MicImageFile(fp=None, filename=None)[source]#

Bases: TiffImageFile

close()[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.

format: str | None = 'MIC'#
format_description: str | None = 'Microsoft Image Composer'#
seek(frame)[source]#

Select a given frame as current image

tell()[source]#

Return the current frame number

MpegImagePlugin Module#

class PIL.MpegImagePlugin.BitStream(fp)[source]#

Bases: object

next()[source]#
peek(bits)[source]#
read(bits)[source]#
skip(bits)[source]#
class PIL.MpegImagePlugin.MpegImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'MPEG'#
format_description: str | None = 'MPEG'#

MspImagePlugin Module#

class PIL.MspImagePlugin.MspDecoder(mode, *args)[source]#

Bases: PyDecoder

decode(buffer)[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 from ImageFile.ERRORS.

class PIL.MspImagePlugin.MspImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'MSP'#
format_description: str | None = 'Windows Paint'#

PalmImagePlugin Module#

PIL.PalmImagePlugin.build_prototype_image()[source]#

PcdImagePlugin Module#

class PIL.PcdImagePlugin.PcdImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'PCD'#
format_description: str | None = 'Kodak PhotoCD'#
load_end()[source]#

PcxImagePlugin Module#

class PIL.PcxImagePlugin.PcxImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'PCX'#
format_description: str | None = 'Paintbrush'#

PdfImagePlugin Module#

PixarImagePlugin Module#

class PIL.PixarImagePlugin.PixarImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'PIXAR'#
format_description: str | None = 'PIXAR raster image'#

PngImagePlugin Module#

class PIL.PngImagePlugin.Blend(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[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.ChunkStream(fp)[source]#

Bases: object

call(cid, pos, length)[source]#

Call the appropriate chunk handler

close()[source]#
crc(cid, data)[source]#

Read and verify checksum

crc_skip(cid, data)[source]#

Read checksum

push(cid, pos, length)[source]#
read()[source]#

Fetch a new chunk. Returns header information.

verify(endchunk=b'IEND')[source]#
class PIL.PngImagePlugin.Disposal(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[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=None, filename=None)[source]#

Bases: ImageFile

getexif()[source]#

Gets EXIF data from the image.

Returns:

an Exif object.

getxmp()[source]#

Returns a dictionary containing the XMP tags. Requires defusedxml to be installed.

Returns:

XMP tags in a dictionary.

load_end()[source]#

internal: finished reading image data

load_prepare()[source]#

internal: prepare to read PNG file

load_read(read_bytes)[source]#

internal: read more image data

seek(frame)[source]#

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 tell().

If defined, n_frames refers 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()[source]#

Returns the current frame number. See seek().

If defined, n_frames refers to the number of available frames.

Returns:

Frame number, starting with 0.

verify()[source]#

Verify PNG file

format: str | None = 'PNG'#
format_description: str | None = 'Portable network graphics'#
property text#
class PIL.PngImagePlugin.PngStream(fp)[source]#

Bases: ChunkStream

check_text_memory(chunklen)[source]#
chunk_IDAT(pos, length)[source]#
chunk_IEND(pos, length)[source]#
chunk_IHDR(pos, length)[source]#
chunk_PLTE(pos, length)[source]#
chunk_acTL(pos, length)[source]#
chunk_cHRM(pos, length)[source]#
chunk_eXIf(pos, length)[source]#
chunk_fcTL(pos, length)[source]#
chunk_fdAT(pos, length)[source]#
chunk_gAMA(pos, length)[source]#
chunk_iCCP(pos, length)[source]#
chunk_iTXt(pos, length)[source]#
chunk_pHYs(pos, length)[source]#
chunk_sRGB(pos, length)[source]#
chunk_tEXt(pos, length)[source]#
chunk_tRNS(pos, length)[source]#
chunk_zTXt(pos, length)[source]#
rewind()[source]#
save_rewind()[source]#
PIL.PngImagePlugin.getchunks(im, **params)[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, cid, *data)[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, *args)[source]#

Bases: PyDecoder

decode(buffer)[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 from ImageFile.ERRORS.

class PIL.PpmImagePlugin.PpmImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'PPM'#
format_description: str | None = 'Pbmplus image'#
class PIL.PpmImagePlugin.PpmPlainDecoder(mode, *args)[source]#

Bases: PyDecoder

decode(buffer)[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 from ImageFile.ERRORS.

PsdImagePlugin Module#

class PIL.PsdImagePlugin.PsdImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'PSD'#
format_description: str | None = 'Adobe Photoshop'#
seek(layer)[source]#

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 tell().

If defined, n_frames refers 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()[source]#

Returns the current frame number. See seek().

If defined, n_frames refers to the number of available frames.

Returns:

Frame number, starting with 0.

SgiImagePlugin Module#

class PIL.SgiImagePlugin.SGI16Decoder(mode, *args)[source]#

Bases: PyDecoder

decode(buffer)[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 from ImageFile.ERRORS.

class PIL.SgiImagePlugin.SgiImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'SGI'#
format_description: str | None = 'SGI Image File Format'#

SpiderImagePlugin Module#

class PIL.SpiderImagePlugin.SpiderImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

convert2byte(depth=255)[source]#
format: str | None = 'SPIDER'#
format_description: str | None = 'Spider 2D image'#
property is_animated#
property n_frames#
seek(frame)[source]#

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 tell().

If defined, n_frames refers 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()[source]#

Returns the current frame number. See seek().

If defined, n_frames refers to the number of available frames.

Returns:

Frame number, starting with 0.

tkPhotoImage()[source]#
PIL.SpiderImagePlugin.isInt(f)[source]#
PIL.SpiderImagePlugin.isSpiderHeader(t)[source]#
PIL.SpiderImagePlugin.isSpiderImage(filename)[source]#
PIL.SpiderImagePlugin.loadImageSeries(filelist=None)[source]#

create a list of Image objects for use in a montage

PIL.SpiderImagePlugin.makeSpiderHeader(im)[source]#

SunImagePlugin Module#

class PIL.SunImagePlugin.SunImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'SUN'#
format_description: str | None = 'Sun Raster File'#

TgaImagePlugin Module#

class PIL.TgaImagePlugin.TgaImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'TGA'#
format_description: str | None = 'Targa'#
load_end()[source]#

TiffImagePlugin Module#

class PIL.TiffImagePlugin.AppendingTiffWriter(fn, new=False)[source]#

Bases: object

Tags = {273, 288, 324, 519, 520, 521}#
close()[source]#
fieldSizes = [0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4, 2, 4, 8]#
finalize()[source]#
fixIFD()[source]#
fixOffsets(count, isShort=False, isLong=False)[source]#
goToEnd()[source]#
newFrame()[source]#
readLong()[source]#
readShort()[source]#
rewriteLastLong(value)[source]#
rewriteLastShort(value)[source]#
rewriteLastShortToLong(value)[source]#
seek(offset, whence=0)[source]#
setEndian(endian)[source]#
setup()[source]#
skipIFDs()[source]#
tell()[source]#
write(data)[source]#
writeLong(value)[source]#
writeShort(value)[source]#
class PIL.TiffImagePlugin.IFDRational(value, denominator=1)[source]#

Bases: Rational

Implements 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

property denominator#
limit_rational(max_denominator)[source]#
Parameters:

max_denominator – Integer, the maximum denominator value

Returns:

Tuple of (numerator, denominator)

property numerator#
PIL.TiffImagePlugin.ImageFileDirectory#

alias of ImageFileDirectory_v1

class PIL.TiffImagePlugin.ImageFileDirectory_v1(*args, **kwargs)[source]#

Bases: ImageFileDirectory_v2

This 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)[source]#

Returns an ImageFileDirectory_v1 instance with the same data as is contained in the original ImageFileDirectory_v2 instance.

Returns:

ImageFileDirectory_v1

property tagdata#
property tags#
tagtype: dict#

Dictionary of tag types

to_v2()[source]#

Returns an ImageFileDirectory_v2 instance with the same data as is contained in the original ImageFileDirectory_v1 instance.

Returns:

ImageFileDirectory_v2

class PIL.TiffImagePlugin.ImageFileDirectory_v2(ifh=b'II*\x00\x00\x00\x00\x00', prefix=None, group=None)[source]#

Bases: MutableMapping

This 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

    New 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 in self._tags_v2 once decoded.

self.legacy_api is a value for internal use, and shouldn’t be changed from outside code. In cooperation with ImageFileDirectory_v1, if legacy_api is true, then decoded tags will be populated into both _tags_v1 and _tags_v2. _tags_v2 will be used if this IFD is used in the TIFF save routine. Tags should be read from _tags_v1 if legacy_api == true.

property legacy_api#
load(fp)[source]#
load_byte(data, legacy_api=True)[source]#
load_double(data, legacy_api=True)#
load_float(data, legacy_api=True)#
load_long(data, legacy_api=True)#
load_long8(data, legacy_api=True)#
load_rational(data, legacy_api=True)[source]#
load_short(data, legacy_api=True)#
load_signed_byte(data, legacy_api=True)#
load_signed_long(data, legacy_api=True)#
load_signed_rational(data, legacy_api=True)[source]#
load_signed_short(data, legacy_api=True)#
load_string(data, legacy_api=True)[source]#
load_undefined(data, legacy_api=True)[source]#
named()[source]#
Returns:

dict of name|key: value

Returns the complete tag dictionary, with named tags where possible.

property offset#
property prefix#
reset()[source]#
save(fp)[source]#
tagtype#

Dictionary of tag types

tobytes(offset=0)[source]#
write_byte(data)[source]#
write_double(*values)#
write_float(*values)#
write_long(*values)#
write_long8(*values)#
write_rational(*values)[source]#
write_short(*values)#
write_signed_byte(*values)#
write_signed_long(*values)#
write_signed_rational(*values)[source]#
write_signed_short(*values)#
write_string(value)[source]#
write_undefined(value)[source]#
class PIL.TiffImagePlugin.TiffImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'TIFF'#
format_description: str | None = 'Adobe TIFF'#
get_photoshop_blocks()[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.

getxmp()[source]#

Returns a dictionary containing the XMP tags. Requires defusedxml to be installed.

Returns:

XMP tags in a dictionary.

load()[source]#

Load image data based on tile list

load_end()[source]#
property n_frames#
seek(frame)[source]#

Select a given frame as current image

tag#

Legacy tag entries

tag_v2#

Image file directory (tag dictionary)

tell()[source]#

Return the current frame number

WebPImagePlugin Module#

class PIL.WebPImagePlugin.WebPImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'WEBP'#
format_description: str | None = 'WebP image'#
getxmp()[source]#

Returns a dictionary containing the XMP tags. Requires defusedxml to be installed.

Returns:

XMP tags in a dictionary.

load()[source]#

Load image data based on tile list

load_seek(pos)[source]#
seek(frame)[source]#

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 tell().

If defined, n_frames refers 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()[source]#

Returns the current frame number. See seek().

If defined, n_frames refers to the number of available frames.

Returns:

Frame number, starting with 0.

WmfImagePlugin Module#

class PIL.WmfImagePlugin.WmfStubImageFile(fp=None, filename=None)[source]#

Bases: StubImageFile

format: str | None = 'WMF'#
format_description: str | None = 'Windows Metafile'#
load(dpi=None)[source]#

Load image data based on tile list

PIL.WmfImagePlugin.register_handler(handler)[source]#

Install application-specific WMF image handler.

Parameters:

handler – Handler object.

XVThumbImagePlugin Module#

class PIL.XVThumbImagePlugin.XVThumbImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'XVThumb'#
format_description: str | None = 'XV thumbnail image'#

XbmImagePlugin Module#

class PIL.XbmImagePlugin.XbmImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'XBM'#
format_description: str | None = 'X11 Bitmap'#

XpmImagePlugin Module#

class PIL.XpmImagePlugin.XpmImageFile(fp=None, filename=None)[source]#

Bases: ImageFile

format: str | None = 'XPM'#
format_description: str | None = 'X11 Pixel Map'#
load_read(bytes)[source]#