9.1.0#

API更改#

执行负裁剪时引发错误#

对以前的图像执行负裁剪刚刚返回一个 (0, 0) 形象。现在,它将提高一个 ValueError ,以帮助在用户无意中提供错误参数时减少混淆。

添加了路径坐标类型不正确时的特定错误#

而不是返回 SystemError ,将不正确类型的坐标传递到路径中将引发更具体的 ValueError ,并显示消息“坐标类型不正确”。

用额外值替换Requirements s.txt#

而不是通过安装文档和测试的所有依赖项 requirements.txtextras_require 而不是使用。这只安装那些需要的,同时安装枕头。

例如:

# Install with dependencies for tests:
python3 -m pip install .[tests]

# Or for building docs:
python3 -m pip install .[docs]

# Or for all:
python3 -m pip install .[docs,tests]

在MacOS上,最后一个参数可能需要用引号括起来,例如 python3 -m pip install ".[tests]"

因此 requirements.txt 已与 make install-req 用于安装其内容的命令。

废弃#

常量#

许多常量已弃用,将在枕头10.0.0(2023-07-01)中删除。相反, enum.IntEnum 已经添加了课程。

备注

其中一些不受欢迎的功能在Pillow 9.4.0中已恢复。看见 常量

已弃用

代替使用

Image.NONE

要么 Image.Dither.NONEImage.Resampling.NEAREST

Image.NEAREST

要么 Image.Dither.NONEImage.Resampling.NEAREST

Image.ORDERED

Image.Dither.ORDERED

Image.RASTERIZE

Image.Dither.RASTERIZE

Image.FLOYDSTEINBERG

Image.Dither.FLOYDSTEINBERG

Image.WEB

Image.Palette.WEB

Image.ADAPTIVE

Image.Palette.ADAPTIVE

Image.AFFINE

Image.Transform.AFFINE

Image.EXTENT

Image.Transform.EXTENT

Image.PERSPECTIVE

Image.Transform.PERSPECTIVE

Image.QUAD

Image.Transform.QUAD

Image.MESH

Image.Transform.MESH

Image.FLIP_LEFT_RIGHT

Image.Transpose.FLIP_LEFT_RIGHT

Image.FLIP_TOP_BOTTOM

Image.Transpose.FLIP_TOP_BOTTOM

Image.ROTATE_90

Image.Transpose.ROTATE_90

Image.ROTATE_180

Image.Transpose.ROTATE_180

Image.ROTATE_270

Image.Transpose.ROTATE_270

Image.TRANSPOSE

Image.Transpose.TRANSPOSE

Image.TRANSVERSE

Image.Transpose.TRANSVERSE

Image.BOX

Image.Resampling.BOX

Image.BILINEAR

Image.Resampling.BILINEAR

Image.LINEAR

Image.Resampling.BILINEAR

Image.HAMMING

Image.Resampling.HAMMING

Image.BICUBIC

Image.Resampling.BICUBIC

Image.CUBIC

Image.Resampling.BICUBIC

Image.LANCZOS

Image.Resampling.LANCZOS

Image.ANTIALIAS

Image.Resampling.LANCZOS

Image.MEDIANCUT

Image.Quantize.MEDIANCUT

Image.MAXCOVERAGE

Image.Quantize.MAXCOVERAGE

Image.FASTOCTREE

Image.Quantize.FASTOCTREE

Image.LIBIMAGEQUANT

Image.Quantize.LIBIMAGEQUANT

ImageCms.INTENT_PERCEPTUAL

ImageCms.Intent.PERCEPTUAL

ImageCms.INTENT_RELATIVE_COLORMETRIC

ImageCms.Intent.RELATIVE_COLORMETRIC

ImageCms.INTENT_SATURATION

ImageCms.Intent.SATURATION

ImageCms.INTENT_ABSOLUTE_COLORIMETRIC

ImageCms.Intent.ABSOLUTE_COLORIMETRIC

ImageCms.DIRECTION_INPUT

ImageCms.Direction.INPUT

ImageCms.DIRECTION_OUTPUT

ImageCms.Direction.OUTPUT

ImageCms.DIRECTION_PROOF

ImageCms.Direction.PROOF

ImageFont.LAYOUT_BASIC

ImageFont.Layout.BASIC

ImageFont.LAYOUT_RAQM

ImageFont.Layout.RAQM

BlpImagePlugin.BLP_FORMAT_JPEG

BlpImagePlugin.Format.JPEG

BlpImagePlugin.BLP_ENCODING_UNCOMPRESSED

BlpImagePlugin.Encoding.UNCOMPRESSED

BlpImagePlugin.BLP_ENCODING_DXT

BlpImagePlugin.Encoding.DXT

BlpImagePlugin.BLP_ENCODING_UNCOMPRESSED_RAW_RGBA

BlpImagePlugin.Encoding.UNCOMPRESSED_RAW_RGBA

BlpImagePlugin.BLP_ALPHA_ENCODING_DXT1

BlpImagePlugin.AlphaEncoding.DXT1

BlpImagePlugin.BLP_ALPHA_ENCODING_DXT3

BlpImagePlugin.AlphaEncoding.DXT3

BlpImagePlugin.BLP_ALPHA_ENCODING_DXT5

BlpImagePlugin.AlphaEncoding.DXT5

FtexImagePlugin.FORMAT_DXT1

FtexImagePlugin.Format.DXT1

FtexImagePlugin.FORMAT_UNCOMPRESSED

FtexImagePlugin.Format.UNCOMPRESSED

PngImagePlugin.APNG_DISPOSE_OP_NONE

PngImagePlugin.Disposal.OP_NONE

PngImagePlugin.APNG_DISPOSE_OP_BACKGROUND

PngImagePlugin.Disposal.OP_BACKGROUND

PngImagePlugin.APNG_DISPOSE_OP_PREVIOUS

PngImagePlugin.Disposal.OP_PREVIOUS

PngImagePlugin.APNG_BLEND_OP_SOURCE

PngImagePlugin.Blend.OP_SOURCE

PngImagePlugin.APNG_BLEND_OP_OVER

PngImagePlugin.Blend.OP_OVER

ImageShow.Viewer.show_file文件参数#

这个 file 中的论点 show_file() 已弃用,将在枕头10.0.0(2023-07-01)中删除。它已被替换为 path

实际上, viewer.show_file("test.jpg") 将继续原封不动地工作。 viewer.show_file(file="test.jpg") 将引发弃用警告,并建议 viewer.show_file(path="test.jpg") 取而代之的是。

FitsStubImagePlugin#

自 9.1.0 版本弃用.

存根图像插件 FitsStubImagePlugin 已弃用,将在枕头10.0.0(2023-07-01)中删除。无需处理器即可读取FITS图像 FitsImagePlugin 取而代之的是。

API添加#

添加了GET_PHOTSHOP_BLOCKS()来解析Photoshop TIFF标签#

get_photoshop_blocks() 已添加,以允许用户确定图像中包含哪些Photoshop“图像资源块”。返回的字典的键是图像资源ID。

目前,每个块中的信息仅作为带有“data”条目的字典返回。这将允许将来添加更多有用的信息,而不会破坏向后兼容性。

添加了用于保存JPEG2000的MCT和NO_JP2选项#

这个 PIL.Image.Image.save() 方法现在支持JPEG2000的以下选项:

mct

如果 1 然后在编码时启用多分量转换,否则使用 0 表示无组件变换(默认)。如果启用了MCT,并且 irreversibleTrue 则将应用不可逆颜色转换,否则编码将使用可逆颜色转换。MCT最适合与 modeRGB 并且仅当图像数据具有3个分量时才适用。

no_jp2

如果 True 则在保存时不要将原始码流包装为JP2文件格式,否则将使用文件的扩展名来确定格式(默认)。

添加了PyEncoder#

PyEncoder 已添加,允许使用Python编写文件编码器。看见 Writing Your Own File Codec in Python 以获取更多信息。

GifImagePlugin加载策略#

Pillow 9.0.0引入了后续GIF帧到 RGBRGBA 。现在可以更改此行为,以便第一个 P 帧被转换为 RGB 也是。**

from PIL import GifImagePlugin
GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_ALWAYS

或者可以将后续帧保存在 P 模式,只要只有一个调色板即可。**

from PIL import GifImagePlugin
GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_AFTER_DIFFERENT_PALETTE_ONLY

其他变化#

Musllinux车轮#

Pillow现在为Musllinux构建二进制轮子,适用于基于MUSL C标准库(而不是许多linux轮子使用的glibc库)的Linux发行版。看见 PEP 656

ImageShow Unix上的临时文件#

当呼叫时 show() 或使用 ImageShow ,则会从该映像创建临时文件。在Unix上,Pillow将不再删除这些文件,而是将其留给操作系统来执行。

Image._repr_pretty_#

im._repr_pretty_ 已经添加,以提供没有对象标识的图像的表示。这允许Jupyter描述图像,并使该描述在相同代码的后续执行中保持不变。

添加了BigTIFF读取#

添加了对读取BigTIFF图像的支持。

增加了BLP节省#

添加了对保存BLP图像的支持。 blp_version 可用于指定图像应保存为BLP1还是BLP2,例如 im.save("out.blp", blp_version="BLP1") 。默认情况下,将使用BLP2。