图像文件格式¶
Python图像库支持多种光栅文件格式。超过30种不同的文件格式,可以识别和图书馆阅读。写支持是那么广泛,但最常见的交流和演示格式的支持。
从他们的内容,而不是他们的名字 open()
功能识别的文件,但在名称 save()
方法看起来,以确定哪些格式的使用,除非格式是明确给出。
完全支持的格式¶
目录
BMP¶
Pillow reads and writes Windows and OS/2 BMP files containing 1
, L
, P
,
or RGB
data. 16-colour images are read as P
images. Run-length encoding
is not supported.
open()
方法集执行以下操作 info
属性:
- 压缩
如果文件被运行长度编码设置为``bmp_rle``.
EPS¶
Pillow identifies EPS files containing image data, and can read files that
contain embedded raster images (ImageData descriptors). If Ghostscript is
available, other EPS files can be read as well. The EPS driver can also write
EPS images. The EPS driver can read EPS images in L
, LAB
, RGB
and
CMYK
mode, but Ghostscript may convert the images to RGB
mode rather
than leaving them in the original color space. The EPS driver can write images
in L
, RGB
and CMYK
modes.
If Ghostscript is available, you can call the load()
method with the following parameter to affect how Ghostscript renders the EPS
- 规模
Affects the scale of the resultant rasterized image. If the EPS suggests that the image be rendered at 100px x 100px, setting this parameter to 2 will make the Ghostscript render a 200px x 200px image instead. The relative position of the bounding box is maintained:
im = Image.open(...) im.size #(100,100) im.load(scale=2) im.size #(200,200)
GIF¶
Pillow reads GIF87a and GIF89a versions of the GIF file format. The library writes run-length encoded files in GIF87a by default, unless GIF89a features are used or GIF89a is already in use.
需要注意的是GIF文件总是读出灰度(L
) 或调色板模式(P
) 图像.
open()
方法集执行以下操作 info
属性:
- background
默认的背景颜色(调色板颜色索引) .
- 透明度
透明色指数. 如果图像是不透明的该键被省略.
- version
Version (either
GIF87a
orGIF89a
).- duration
可能不存在. 的时间,以显示GIF的当前帧,以毫秒为单位.
- loop
可能不存在. 时代的GIF应该循环的数量. 0意味着它将永远循环下去.
- comment
可能不存在. 有关图像的注释.
- extension
可能不存在. 包含应用程序的具体信息.
读出序列¶
The GIF loader supports the seek()
and
tell()
methods. You can combine these methods
to seek to the next frame (im.seek(im.tell() + 1)
).
Saving¶
当调用:PY:甲基:`〜PIL.Image.Image.save`写一个GIF文件,下列选项可用:
im.save(out, save_all=True, append_images=[im1, im2, ...])
- save_all
如果存在,真实,图像的所有帧将被保存. 如果没有,那么只有一个多帧图像的第一帧将被保存.
- append_images
A list of images to append as additional frames. Each of the images in the list can be single or multiframe images. This is currently supported for GIF, PDF, TIFF, and WebP.
它也支持ICNS. 如果图像相关尺寸的通过,他们将被用来代替缩小主图像.
- include_color_table
Whether or not to include local color table.
- interlace
无论图像交错. 默认情况下,它是,除非图像的宽度或高度小于16个像素.
- disposal
指示其中图形是被显示之后,待处理的方式.
0 - No disposal specified.
1 - Do not dispose.
2 - Restore to background color.
3 - Restore to previous content.
通过对于恒定的处置的单一的整数,或列表或元组分别设定处置对于每个帧.
- palette
Use the specified palette for the saved image. The palette should be a bytes or bytearray object containing the palette entries in RGBRGB… form. It should be no more than 768 bytes. Alternately, the palette can be passed in as an
PIL.ImagePalette.ImagePalette
object.- optimize
If present and true, attempt to compress the palette by eliminating unused colors. This is only useful if the palette can be compressed to the next smaller power of 2 elements.
Note that if the image you are saving comes from an existing GIF, it may have
the following properties in its info
dictionary.
For these options, if you do not pass them in, they will default to
their info
values.
- 透明度
Transparency color index.
- duration
The display duration of each frame of the multiframe gif, in milliseconds. Pass a single integer for a constant duration, or a list or tuple to set the duration for each frame separately.
- loop
整数次数的GIF应该循环. 0意味着它将永远循环下去. 默认情况下,图像将无法循环.
- comment
A comment about the image.
Reading local images¶
The GIF loader creates an image memory the same size as the GIF file’s logical
screen size, and pastes the actual pixel data (the local image) into this
image. If you only want the actual pixel rectangle, you can manipulate the
size
and tile
attributes before loading the file:
im = Image.open(...)
if im.tile[0][0] == "gif":
# only read the first "local image" from this GIF file
tag, (x0, y0, x1, y1), offset, extra = im.tile[0]
im.size = (x1 - x0, y1 - y0)
im.tile = [(tag, (0, 0) + im.size, offset, extra)]
ICNS¶
Pillow reads and (macOS only) writes macOS .icns
files. By default, the
largest available icon is read, though you can override this by setting the
size
property before calling
load()
. The open()
method
sets the following info
property:
- sizes
A list of supported sizes found in this icon file; these are a 3-tuple,
(width, height, scale)
, wherescale
is 2 for a retina icon and 1 for a standard icon. You are permitted to use this 3-tuple format for thesize
property if you set it before callingload()
; after loading, the size will be reset to a 2-tuple containing pixel dimensions (so, e.g. if you ask for(512, 512, 2)
, the final value ofsize
will be(1024, 1024)
).
The save()
method can take the following keyword arguments:
- append_images
A list of images to replace the scaled down versions of the image. The order of the images does not matter, as their use is determined by the size of each image.
5.1.0 新版功能.
ICO¶
ICO用于在Windows应用商店图标. 最大可用图标被读取.
The save()
method supports the following options:
- sizes
A list of sizes including in this ico file; these are a 2-tuple,
(width, height)
; Default to[(16, 16), (24, 24), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)]
. Any sizes bigger than the original size or 256 will be ignored.
IM¶
IM is a format used by LabEye and other applications based on the IFUNC image processing library. The library reads and writes most uncompressed interchange versions of this format.
IM是可以存储所有内部 Pillow 格式的唯一格式.
JPEG¶
Pillow 读取JPEG,JFIF和Adobe JPEG文件包含``L``,RGB
,或``CMYK``数据. 它写入标准和渐进JFIF文件.
Using the draft()
method, you can speed things up by
converting RGB
images to L
, and resize images to 1/2, 1/4 or 1/8 of
their original size while loading them.
The open()
method may set the following
info
properties if available:
- jfif
JFIF应用标记发现. 如果文件不是一个JFIF文件,这个键不存在.
- jfif_version
A tuple representing the jfif version, (major version, minor version).
- jfif_density
A tuple representing the pixel density of the image, in units specified by jfif_unit.
- jfif_unit
Units for the jfif_density:
0 - No Units
1 - Pixels per Inch
2 - Pixels per Centimeter
- dpi
A tuple representing the reported pixel density in pixels per inch, if the file is a jfif file and the units are in inches.
- adobe
Adobe application marker found. If the file is not an Adobe JPEG file, this key is not present.
- adobe_transform
Vendor Specific Tag.
- progression
Indicates that this is a progressive JPEG file.
- icc_profile
The ICC color profile for the image.
- exif
Raw EXIF data from the image.
The save()
method supports the following options:
- quality
The image quality, on a scale from 1 (worst) to 95 (best). The default is 75. Values above 95 should be avoided; 100 disables portions of the JPEG compression algorithm, and results in large files with hardly any gain in image quality.
- optimize
If present and true, indicates that the encoder should make an extra pass over the image in order to select optimal encoder settings.
- progressive
If present and true, indicates that this image should be stored as a progressive JPEG file.
- dpi
A tuple of integers representing the pixel density,
(x,y)
.- icc_profile
If present and true, the image is stored with the provided ICC profile. If this parameter is not provided, the image will be saved with no profile attached. To preserve the existing profile:
im.save(filename, 'jpeg', icc_profile=im.info.get('icc_profile'))
- exif
If present, the image will be stored with the provided raw EXIF data.
- subsampling
If present, sets the subsampling for the encoder.
keep
: Only valid for JPEG files, will retain the original image setting.4:4:4
,4:2:2
,4:2:0
: Specific sampling values-1
: equivalent tokeep
0
: equivalent to4:4:4
1
: equivalent to4:2:2
2
: equivalent to4:2:0
- qtables
If present, sets the qtables for the encoder. This is listed as an advanced option for wizards in the JPEG documentation. Use with caution.
qtables
can be one of several types of values:a string, naming a preset, e.g.
keep
,web_low
, orweb_high
a list, tuple, or dictionary (with integer keys = range(len(keys))) of lists of 64 integers. There must be between 2 and 4 tables.
2.5.0 新版功能.
注解
To enable JPEG support, you need to build and install the IJG JPEG library before building the Python Imaging Library. See the distribution README for details.
JPEG 2000¶
2.4.0 新版功能.
Pillow reads and writes JPEG 2000 files containing L
, LA
, RGB
or
RGBA
data. It can also read files containing YCbCr
data, which it
converts on read into RGB
or RGBA
depending on whether or not there is
an alpha channel. Pillow supports JPEG 2000 raw codestreams (.j2k
files),
as well as boxed JPEG 2000 files (.j2p
or .jpx
files). Pillow does
not support files whose components have different sampling frequencies.
When loading, if you set the mode
on the image prior to the
load()
method being invoked, you can ask Pillow to
convert the image to either RGB
or RGBA
rather than choosing for
itself. It is also possible to set reduce
to the number of resolutions to
discard (each one reduces the size of the resulting image by a factor of 2),
and layers
to specify the number of quality layers to load.
The save()
method supports the following options:
- offset
The image offset, as a tuple of integers, e.g. (16, 16)
- tile_offset
The tile offset, again as a 2-tuple of integers.
- tile_size
The tile size as a 2-tuple. If not specified, or if set to None, the image will be saved without tiling.
- quality_mode
Either
"rates"
or"dB"
depending on the units you want to use to specify image quality.- quality_layers
A sequence of numbers, each of which represents either an approximate size reduction (if quality mode is
"rates"
) or a signal to noise ratio value in decibels. If not specified, defaults to a single layer of full quality.- num_resolutions
The number of different image resolutions to be stored (which corresponds to the number of Discrete Wavelet Transform decompositions plus one).
- codeblock_size
The code-block size as a 2-tuple. Minimum size is 4 x 4, maximum is 1024 x 1024, with the additional restriction that no code-block may have more than 4096 coefficients (i.e. the product of the two numbers must be no greater than 4096).
- precinct_size
The precinct size as a 2-tuple. Must be a power of two along both axes, and must be greater than the code-block size.
- irreversible
If
True
, use the lossy Irreversible Color Transformation followed by DWT 9-7. Defaults toFalse
, which means to use the Reversible Color Transformation with DWT 5-3.- progression
Controls the progression order; must be one of
"LRCP"
,"RLCP"
,"RPCL"
,"PCRL"
,"CPRL"
. The letters stand for Component, Position, Resolution and Layer respectively and control the order of encoding, the idea being that e.g. an image encoded using LRCP mode can have its quality layers decoded as they arrive at the decoder, while one encoded using RLCP mode will have increasing resolutions decoded as they arrive, and so on.- cinema_mode
Set the encoder to produce output compliant with the digital cinema specifications. The options here are
"no"
(the default),"cinema2k-24"
for 24fps 2K,"cinema2k-48"
for 48fps 2K, and"cinema4k-24"
for 24fps 4K. Note that for compliant 2K files, at least one of your image dimensions must match 2048 x 1080, while for compliant 4K files, at least one of the dimensions must match 4096 x 2160.
注解
To enable JPEG 2000 support, you need to build and install the OpenJPEG library, version 2.0.0 or higher, before building the Python Imaging Library.
Windows users can install the OpenJPEG binaries available on the
OpenJPEG website, but must add them to their PATH in order to use Pillow (if
you fail to do this, you will get errors about not being able to load the
_imaging
DLL).
MSP¶
Pillow identifies and reads MSP files from Windows 1 and 2. The library writes uncompressed (Windows 1) versions of this format.
PNG¶
Pillow identifies, reads, and writes PNG files containing 1
, L
, LA
,
I
, P
, RGB
or RGBA
data. Interlaced files are supported as of
v1.1.7.
As of Pillow 6.0, EXIF data can be read from PNG images. However, unlike other
image formats, EXIF data is not guaranteed to be present in
info
until load()
has been
called.
The open()
method sets the following
info
properties, when appropriate:
- chromaticity
The chromaticity points, as an 8 tuple of floats. (
White Point X
,White Point Y
,Red X
,Red Y
,Green X
,Green Y
,Blue X
,Blue Y
)- gamma
Gamma, given as a floating point number.
- srgb
The sRGB rendering intent as an integer.
0 Perceptual
1 Relative Colorimetric
2 Saturation
3 Absolute Colorimetric
- 透明度
For
P
images: Either the palette index for full transparent pixels, or a byte string with alpha values for each palette entry.For
1
,L
,I
andRGB
images, the color that represents full transparent pixels in this image.This key is omitted if the image is not a transparent palette image.
open
also sets Image.text
to a dictionary of the values of the
tEXt
, zTXt
, and iTXt
chunks of the PNG image. Individual
compressed chunks are limited to a decompressed size of
PngImagePlugin.MAX_TEXT_CHUNK
, by default 1MB, to prevent
decompression bombs. Additionally, the total size of all of the text
chunks is limited to PngImagePlugin.MAX_TEXT_MEMORY
, defaulting to
64MB.
The save()
method supports the following options:
- optimize
If present and true, instructs the PNG writer to make the output file as small as possible. This includes extra processing in order to find optimal encoder settings.
- 透明度
For
P
,1
,L
,I
, andRGB
images, this option controls what color from the image to mark as transparent.For
P
images, this can be a either the palette index, or a byte string with alpha values for each palette entry.- dpi
A tuple of two numbers corresponding to the desired dpi in each direction.
- pnginfo
A
PIL.PngImagePlugin.PngInfo
instance containing text tags.- compress_level
ZLIB compression level, a number between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all. Default is 6. When
optimize
option is Truecompress_level
has no effect (it is set to 9 regardless of a value passed).- icc_profile
The ICC Profile to include in the saved file.
- exif
The exif data to include in the saved file.
6.0.0 新版功能.
- bits (experimental)
For
P
images, this option controls how many bits to store. If omitted, the PNG writer uses 8 bits (256 colors).- dictionary (experimental)
Set the ZLIB encoder dictionary.
注解
To enable PNG support, you need to build and install the ZLIB compression library before building the Python Imaging Library. See the installation documentation for details.
SPIDER¶
Pillow reads and writes SPIDER image files of 32-bit floating point data (“F;32F”).
Pillow also reads SPIDER stack files containing sequences of SPIDER images. The
seek()
and tell()
methods are supported, and
random access is allowed.
The open()
method sets the following attributes:
- format
Set to
SPIDER
- istack
Set to 1 if the file is an image stack, else 0.
- n_frames
Set to the number of images in the stack.
A convenience method, convert2byte()
, is provided for
converting floating point data to byte data (mode L
):
im = Image.open('image001.spi').convert2byte()
Writing files in SPIDER format¶
The extension of SPIDER files may be any 3 alphanumeric characters. Therefore the output format must be specified explicitly:
im.save('newimage.spi', format='SPIDER')
For more information about the SPIDER image processing package, see the SPIDER homepage at Wadsworth Center.
TGA¶
Pillow reads and writes TGA images containing L
, LA
, P
,
RGB
, and RGBA
data. Pillow can read and write both uncompressed and
run-length encoded TGAs.
TIFF¶
Pillow reads and writes TIFF files. It can read both striped and tiled images, pixel and plane interleaved multi-band images. If you have libtiff and its headers installed, Pillow can read and write many kinds of compressed TIFF files. If not, Pillow will only read and write uncompressed files.
注解
Beginning in version 5.0.0, Pillow requires libtiff to read or write compressed files. Prior to that release, Pillow had buggy support for reading Packbits, LZW and JPEG compressed TIFFs without using libtiff.
open()
方法集执行以下操作 info
属性:
- 压缩
Compression mode.
2.0.0 新版功能.
- dpi
Image resolution as an
(xdpi, ydpi)
tuple, where applicable. You can use thetag
attribute to get more detailed information about the image resolution.1.1.5 新版功能.
- resolution
Image resolution as an
(xres, yres)
tuple, where applicable. This is a measurement in whichever unit is specified by the file.1.1.5 新版功能.
The tag_v2
attribute contains a dictionary
of TIFF metadata. The keys are numerical indexes from
TAGS_V2
. Values are strings or numbers for single
items, multiple values are returned in a tuple of values. Rational
numbers are returned as a IFDRational
object.
3.0.0 新版功能.
For compatibility with legacy code, the
tag
attribute contains a dictionary of
decoded TIFF fields as returned prior to version 3.0.0. Values are
returned as either strings or tuples of numeric values. Rational
numbers are returned as a tuple of (numerator, denominator)
.
3.0.0 版后已移除.
Reading Multi-frame TIFF Images¶
The TIFF loader supports the seek()
and
tell()
methods, taking and returning frame numbers
within the image file. You can combine these methods to seek to the next frame
(im.seek(im.tell() + 1)
). Frames are numbered from 0 to im.num_frames - 1
,
and can be accessed in any order.
Saving Tiff Images¶
The save()
method can take the following keyword arguments:
- save_all
If true, Pillow will save all frames of the image to a multiframe tiff document.
3.4.0 新版功能.
- append_images
A list of images to append as additional frames. Each of the images in the list can be single or multiframe images. Note however, that for correct results, all the appended images should have the same
encoderinfo
andencoderconfig
properties.4.2.0 新版功能.
- tiffinfo
A
ImageFileDirectory_v2
object or dict object containing tiff tags and values. The TIFF field type is autodetected for Numeric and string values, any other types require using anImageFileDirectory_v2
object and setting the type intagtype
with the appropriate numerical value fromTiffTags.TYPES
.2.3.0 新版功能.
Metadata values that are of the rational type should be passed in using a
IFDRational
object.3.1.0 新版功能.
For compatibility with legacy code, a
ImageFileDirectory_v1
object may be passed in this field. However, this is deprecated.5.4.0 新版功能.
Previous versions only supported some tags when writing using libtiff. The supported list is found in
LIBTIFF_CORE
.6.1.0 新版功能.
Added support for signed types (e.g.
TIFF_SIGNED_LONG
) and multiple values. Multiple values for a single tag must be toImageFileDirectory_v2
as a tuple and require a matching type intagtype
tagtype.- 压缩
A string containing the desired compression method for the file. (valid only with libtiff installed) Valid compression methods are:
None
,"tiff_ccitt"
,"group3"
,"group4"
,"tiff_jpeg"
,"tiff_adobe_deflate"
,"tiff_thunderscan"
,"tiff_deflate"
,"tiff_sgilog"
,"tiff_sgilog24"
,"tiff_raw_16"
- quality
The image quality for JPEG compression, on a scale from 0 (worst) to 100 (best). The default is 75.
6.1.0 新版功能.
These arguments to set the tiff header fields are an alternative to using the general tags available through tiffinfo.
description
software
date_time
artist
- copyright
Strings
- resolution_unit
An integer. 1 for no unit, 2 for inches and 3 for centimeters.
- resolution
Either an integer or a float, used for both the x and y resolution.
- x_resolution
Either an integer or a float.
- y_resolution
Either an integer or a float.
- dpi
A tuple of (x_resolution, y_resolution), with inches as the resolution unit. For consistency with other image formats, the x and y resolutions of the dpi will be rounded to the nearest integer.
WebP¶
Pillow reads and writes WebP files. The specifics of Pillow’s capabilities with this format are currently undocumented.
The save()
method supports the following options:
- lossless
If present and true, instructs the WebP writer to use lossless compression.
- quality
Integer, 1-100, Defaults to 80. For lossy, 0 gives the smallest size and 100 the largest. For lossless, this parameter is the amount of effort put into the compression: 0 is the fastest, but gives larger files compared to the slowest, but best, 100.
- method
Quality/speed trade-off (0=fast, 6=slower-better). Defaults to 0.
- icc_profile
The ICC Profile to include in the saved file. Only supported if the system WebP library was built with webpmux support.
- exif
The exif data to include in the saved file. Only supported if the system WebP library was built with webpmux support.
Saving sequences¶
注解
Support for animated WebP files will only be enabled if the system WebP
library is v0.5.0 or later. You can check webp animation support at
runtime by calling features.check("webp_anim")
.
When calling save()
to write a WebP file, the
following options are available when the save_all
argument is present and
true.
- append_images
A list of images to append as additional frames. Each of the images in the list can be single or multiframe images.
- duration
The display duration of each frame, in milliseconds. Pass a single integer for a constant duration, or a list or tuple to set the duration for each frame separately.
- loop
Number of times to repeat the animation. Defaults to [0 = infinite].
- background
Background color of the canvas, as an RGBA tuple with values in the range of (0-255).
- minimize_size
If true, minimize the output size (slow). Implicitly disables key-frame insertion.
- kmin, kmax
Minimum and maximum distance between consecutive key frames in the output. The library may insert some key frames as needed to satisfy this criteria. Note that these conditions should hold: kmax > kmin and kmin >= kmax / 2 + 1. Also, if kmax <= 0, then key-frame insertion is disabled; and if kmax == 1, then all frames will be key-frames (kmin value does not matter for these special cases).
- allow_mixed
If true, use mixed compression mode; the encoder heuristically chooses between lossy and lossless for each frame.
Read-only formats¶
BLP¶
BLP is the Blizzard Mipmap Format, a texture format used in World of
Warcraft. Pillow supports reading JPEG
Compressed or raw BLP1
images, and all types of BLP2
images.
CUR¶
CUR is used to store cursors on Windows. The CUR decoder reads the largest available cursor. Animated cursors are not supported.
DCX¶
DCX is a container file format for PCX files, defined by Intel. The DCX format
is commonly used in fax applications. The DCX decoder can read files containing
1
, L
, P
, or RGB
data.
When the file is opened, only the first image is read. You can use
seek()
or ImageSequence
to read other images.
DDS¶
DDS is a popular container texture format used in video games and natively
supported by DirectX.
Currently, uncompressed RGB data and DXT1, DXT3, and DXT5 pixel formats are
supported, and only in RGBA
mode.
3.4.0 新版功能: DXT3
FLI, FLC¶
Pillow reads Autodesk FLI and FLC animations.
open()
方法集执行以下操作 info
属性:
- duration
The delay (in milliseconds) between each frame.
FPX¶
Pillow reads Kodak FlashPix files. In the current version, only the highest resolution image is read from the file, and the viewing transform is not taken into account.
注解
To enable full FlashPix support, you need to build and install the IJG JPEG library before building the Python Imaging Library. See the distribution README for details.
FTEX¶
3.2.0 新版功能.
The FTEX decoder reads textures used for 3D objects in Independence War 2: Edge Of Chaos. The plugin reads a single texture per file, in the compressed and uncompressed formats.
GBR¶
The GBR decoder reads GIMP brush files, version 1 and 2.
open()
方法集执行以下操作 info
属性:
- comment
The brush name.
- spacing
The spacing between the brushes, in pixels. Version 2 only.
GD¶
Pillow reads uncompressed GD2 files. Note that you must use
PIL.GdImageFile.open()
to read such a file.
open()
方法集执行以下操作 info
属性:
- 透明度
透明色指数. 如果图像是不透明的该键被省略.
MIC¶
Pillow identifies and reads Microsoft Image Composer (MIC) files. When opened,
the first sprite in the file is loaded. You can use seek()
and
tell()
to read other sprites from the file.
Note that there may be an embedded gamma of 2.2 in MIC files.
MPO¶
Pillow identifies and reads Multi Picture Object (MPO) files, loading the primary
image when first opened. The seek()
and tell()
methods may be used to read other pictures from the file. The pictures are
zero-indexed and random access is supported.
PCD¶
Pillow reads PhotoCD files containing RGB
data. This only reads the 768x512
resolution image from the file. Higher resolutions are encoded in a proprietary
encoding.
PIXAR¶
Pillow provides limited support for PIXAR raster files. The library can identify and read “dumped” RGB files.
The format code is PIXAR
.
WAL¶
1.1.4 新版功能.
Pillow reads Quake2 WAL texture files.
Note that this file format cannot be automatically identified, so you must use
the open function in the WalImageFile
module to read files in
this format.
By default, a Quake2 standard palette is attached to the texture. To override the palette, use the putpalette method.
WMF¶
Pillow can identify WMF files.
On Windows, it can read WMF files. By default, it will load the image at 72 dpi. To load it at another resolution:
from PIL import Image
with Image.open("drawing.wmf") as im:
im.load(dpi=144)
To add other read or write support, use
PIL.WmfImagePlugin.register_handler()
to register a WMF handler.
from PIL import Image
from PIL import WmfImagePlugin
class WmfHandler:
def open(self, im):
...
def load(self, im):
...
return image
def save(self, im, fp, filename):
...
wmf_handler = WmfHandler()
WmfImagePlugin.register_handler(wmf_handler)
im = Image.open("sample.wmf")
Write-only formats¶
PALM¶
Pillow provides write-only support for PALM pixmap files.
The format code is Palm
, the extension is .palm
.
PDF¶
Pillow can write PDF (Acrobat) images. Such images are written as binary PDF 1.4 files, using either JPEG or HEX encoding depending on the image mode (and whether JPEG support is available or not).
The save()
method can take the following keyword arguments:
- save_all
If a multiframe image is used, by default, only the first image will be saved. To save all frames, each frame to a separate page of the PDF, the
save_all
parameter must be present and set toTrue
.3.0.0 新版功能.
- append_images
A list of images to append as additional pages. Each of the images in the list can be single or multiframe images.
4.2.0 新版功能.
- append
Set to True to append pages to an existing PDF file. If the file doesn’t exist, an
IOError
will be raised.5.1.0 新版功能.
- resolution
Image resolution in DPI. This, together with the number of pixels in the image, will determine the physical dimensions of the page that will be saved in the PDF.
- title
The document’s title. If not appending to an existing PDF file, this will default to the filename.
5.1.0 新版功能.
- author
The name of the person who created the document.
5.1.0 新版功能.
- subject
The subject of the document.
5.1.0 新版功能.
- keywords
Keywords associated with the document.
5.1.0 新版功能.
- creator
If the document was converted to PDF from another format, the name of the conforming product that created the original document from which it was converted.
5.1.0 新版功能.
- producer
If the document was converted to PDF from another format, the name of the conforming product that converted it to PDF.
5.1.0 新版功能.
- creationDate
The creation date of the document. If not appending to an existing PDF file, this will default to the current time.
5.3.0 新版功能.
- modDate
The modification date of the document. If not appending to an existing PDF file, this will default to the current time.
5.3.0 新版功能.
XV Thumbnails¶
Pillow can read XV thumbnail files.
Identify-only formats¶
BUFR¶
1.1.3 新版功能.
Pillow provides a stub driver for BUFR files.
To add read or write support to your application, use
PIL.BufrStubImagePlugin.register_handler()
.
FITS¶
1.1.5 新版功能.
Pillow provides a stub driver for FITS files.
To add read or write support to your application, use
PIL.FitsStubImagePlugin.register_handler()
.
GRIB¶
1.1.5 新版功能.
Pillow provides a stub driver for GRIB files.
The driver requires the file to start with a GRIB header. If you have files with embedded GRIB data, or files with multiple GRIB fields, your application has to seek to the header before passing the file handle to Pillow.
To add read or write support to your application, use
PIL.GribStubImagePlugin.register_handler()
.
HDF5¶
1.1.5 新版功能.
Pillow provides a stub driver for HDF5 files.
To add read or write support to your application, use
PIL.Hdf5StubImagePlugin.register_handler()
.