弃用和移除#

本页列出了不推荐使用的Pillow功能,或在过去的主要版本中删除的Pillow功能,并给出了替代使用的选项。

不推荐使用的功能#

以下是被视为已弃用的功能。在适当的情况下,a DeprecationWarning 发行。

PSFile#

自 9.5.0 版本弃用.

这个 PSFile 类已弃用,将在枕头11(2024-10-15)中删除。此类仅用作内部使用的帮助器,因此没有替代类。如果您需要此功能,那么它是一个非常短的类,可以很容易地在您自己的代码中重新创建。

PyAccess和Image.USE_CFFI_Access#

自 10.0.0 版本弃用.

由于Pillow的C API现在比PyPy上的PyAccess更快, PyAccess 已弃用,将在枕头11.0.0(2024-10-15)中删除。Pillow的C API现在将在PyPy上默认使用。

Image.USE_CFFI_ACCESS ,用于从C API切换到PyAccess,同样不推荐使用。

删除的功能#

不推荐使用的功能只有在经过适当的不推荐期之后才能在主要版本中删除。

Tk/Tcl 8.4#

自 8.2.0 版本弃用.

Removed in version 10.0.0.

在Pillow 10.0.0(2023-07-01)中删除了对Tk/TCL 8.4的支持。

类别#

自 8.2.0 版本弃用.

Removed in version 10.0.0.

im.category 已与相关的 Image.NORMALImage.SEQUENCEImage.CONTAINER 属性。

为了确定图像是否具有多个帧, getattr(im, "is_animated", False) 可以改为使用。

JpegImagePlugin.convert_dict_qtables#

自 8.3.0 版本弃用.

Removed in version 10.0.0.

自Pillow 8.3.0中的弃用以来, convert_dict_qtables 方法不再对提供给它的数据执行任何操作,并且已被移除。

ImagePalette大小参数#

自 8.4.0 版本弃用.

Removed in version 10.0.0.

在Pillow 8.3.0之前, ImagePalette 默认情况下需要特定长度的调色板数据,而 size 参数可以用来覆盖它。Pillow 8.3.0删除了默认的所需长度,也不再需要 size 参数。

ImageShow.Viewer.show_file文件参数#

自 9.1.0 版本弃用.

Removed in version 10.0.0.

这个 file 中的论点 show_file() 已被移除,并被替换为 path

实际上, viewer.show_file("test.jpg") 将继续原封不动地工作。

常量#

自 9.1.0 版本弃用.

Removed in version 10.0.0.

一些常量已被删除。相反, enum.IntEnum 已经添加了课程。

备注

其他内容 Image 常量在Pillow 9.1.0中已弃用,但在Pillow 9.4.0中则相反,这些常量现在仍将可用。看见 常量

远离的

代替使用

Image.LINEAR

Image.BILINEAR or Image.Resampling.BILINEAR

Image.CUBIC

Image.BICUBIC or Image.Resampling.BICUBIC

Image.ANTIALIAS

Image.LANCZOS or Image.Resampling.LANCZOS

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

FitsStubImagePlugin#

自 9.1.0 版本弃用.

Removed in version 10.0.0.

存根图像插件 FitsStubImagePlugin 已被移除。无需处理器即可读取FITS图像 FitsImagePlugin 取而代之的是。

字体大小和偏移方法#

自 9.2.0 版本弃用.

Removed in version 10.0.0.

删除了几个用于计算呈现文本的大小和偏移量的函数:

远离的

代替使用

FreeTypeFont.getsize() and FreeTypeFont.getoffset()

FreeTypeFont.getbbox() and FreeTypeFont.getlength()

FreeTypeFont.getsize_multiline()

ImageDraw.multiline_textbbox()

ImageFont.getsize()

ImageFont.getbbox() and ImageFont.getlength()

TransposedFont.getsize()

TransposedFont.getbbox() and TransposedFont.getlength()

ImageDraw.textsize() and ImageDraw.multiline_textsize()

ImageDraw.textbbox(), ImageDraw.textlength() and ImageDraw.multiline_textbbox()

ImageDraw2.Draw.textsize()

ImageDraw2.Draw.textbbox() and ImageDraw2.Draw.textlength()

以前的代码::

from PIL import Image, ImageDraw, ImageFont

font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")
width, height = font.getsize("Hello world")
left, top = font.getoffset("Hello world")

im = Image.new("RGB", (100, 100))
draw = ImageDraw.Draw(im)
width, height = draw.textsize("Hello world")

width, height = font.getsize_multiline("Hello\nworld")
width, height = draw.multiline_textsize("Hello\nworld")

改用::

from PIL import Image, ImageDraw, ImageFont

font = ImageFont.truetype("Tests/fonts/FreeMono.ttf")
left, top, right, bottom = font.getbbox("Hello world")
width, height = right - left, bottom - top

im = Image.new("RGB", (100, 100))
draw = ImageDraw.Draw(im)
width = draw.textlength("Hello world")

left, top, right, bottom = draw.multiline_textbbox((0, 0), "Hello\nworld")
width, height = right - left, bottom - top

FreeTypeFont.getmask2填充参数#

自 9.2.0 版本弃用.

Removed in version 10.0.0.

未登记的人 fill 的参数 FreeTypeFont.getmask2() 已被移除。

PhotoImage.Paste box参数#

自 9.2.0 版本弃用.

Removed in version 10.0.0.

这个 box 参数未使用,已被删除。

PyQt5和PySide2#

自 9.2.0 版本弃用.

Removed in version 10.0.0.

Qt 5 reached end-of-life 对于开源用户,将于2020-12-08年月到期(对于商业许可证持有者,将于2023-12-08年年达到停产)。

已从中删除对PyQt5和PySide2的支持 ImageQt 。升级到 PyQt6PySide6 取而代之的是。

Image.coerce_e#

自 9.2.0 版本弃用.

Removed in version 10.0.0.

此未记录的方法已被删除。

Pillow版本常数#

自 5.2.0 版本弃用.

Removed in version 9.0.0.

使用 __version__ 取而代之的是。

它最初在Pillow 7.0.0中被删除,但在7.1.0中临时恢复,以便给项目更多时间进行升级。

图像.show命令参数#

自 7.2.0 版本弃用.

Removed in version 9.0.0.

这个 command 参数已删除。使用的子类 ImageShow.Viewer 取而代之的是。

Image._showxv#

自 7.2.0 版本弃用.

Removed in version 9.0.0.

使用 Image.Image.show() 取而代之的是。如果需要自定义行为,请使用 ImageShow.register() 添加自定义的步骤 ImageShow.Viewer 班级。

ImageFile.raise_ioerror#

自 7.2.0 版本弃用.

Removed in version 9.0.0.

IOError 被合并到 OSError 在Python3.3中。所以, ImageFile.raise_ioerror 已被移除。使用 ImageFile.raise_oserror 取而代之的是。

FreeType 2.7#

自 8.1.0 版本弃用.

Removed in version 9.0.0.

已移除对FreeType 2.7的支持。

我们建议至少升级到 FreeType 2.10.4,修复了在FreeType 2.6中引入的一个严重漏洞 (CVE-2020-15999 )。

im.offset#

自 1.1.2 版本弃用.

Removed in version 8.0.0.

im.offset() 已被删除,呼叫 ImageChops.offset() 相反。

在PIL 1.1.2中记录为已弃用,引发了 DeprecationWarning 从1.1.5开始 Exception 因为枕头3.0.0和 NotImplementedError 从3.3.0开始。

图像.fromstring, 来自字符串的im以及im.tostring公司#

自 2.0.0 版本弃用.

Removed in version 8.0.0.

  • Image.fromstring() 已被删除,呼叫 Image.frombytes() 相反。

  • im.fromstring() 已被删除,呼叫 frombytes() 相反。

  • im.tostring() 已被删除,呼叫 tobytes() 相反。

他们发出了 DeprecationWarning 从2.0.0开始 Exception 自3.0.0和 NotImplementedError 从3.3.0开始。

imagecms.cmsprofile属性#

自 3.2.0 版本弃用.

Removed in version 8.0.0.

中的一些属性 PIL.ImageCms.CmsProfile 已被删除。从6.0.0开始,他们发布了一个 DeprecationWarning

远离的

代替使用

color_space

加垫的 xcolor_space

pcs

加垫的 connection_space

product_copyright

统一码 copyright

product_desc

统一码 profile_description

product_description

统一码 profile_description

product_manufacturer

统一码 manufacturer

product_model

统一码 model

Python 2.7#

自 6.0.0 版本弃用.

Removed in version 7.0.0.

Python2.7在2020年1月1日达到了生命的尽头。Pillow6.x是支持Python2的最后一个系列。

Image.__del__#

自 6.1.0 版本弃用.

Removed in version 7.0.0.

在中隐式关闭图像的基础文件 Image.__del__ 已删除。使用上下文管理器或调用 Image.close() 而是以确定的方式关闭文件。

前一种方法::

im = Image.open("hopper.png")
im.save("out.jpg")

改用::

with Image.open("hopper.png") as im:
    im.save("out.jpg")

pil.*imageplugin.u版本属性#

自 6.0.0 版本弃用.

Removed in version 7.0.0.

单个插件的版本常量已被删除。使用 PIL.__version__ 相反。

远离的

远离的

远离的

BmpImagePlugin.__version__

Jpeg2KImagePlugin.__version__

PngImagePlugin.__version__

CurImagePlugin.__version__

JpegImagePlugin.__version__

PpmImagePlugin.__version__

DcxImagePlugin.__version__

McIdasImagePlugin.__version__

PsdImagePlugin.__version__

EpsImagePlugin.__version__

MicImagePlugin.__version__

SgiImagePlugin.__version__

FliImagePlugin.__version__

MpegImagePlugin.__version__

SunImagePlugin.__version__

FpxImagePlugin.__version__

MpoImagePlugin.__version__

TgaImagePlugin.__version__

GdImageFile.__version__

MspImagePlugin.__version__

TiffImagePlugin.__version__

GifImagePlugin.__version__

PalmImagePlugin.__version__

WmfImagePlugin.__version__

IcoImagePlugin.__version__

PcdImagePlugin.__version__

XbmImagePlugin.__version__

ImImagePlugin.__version__

PcxImagePlugin.__version__

XpmImagePlugin.__version__

ImtImagePlugin.__version__

PdfImagePlugin.__version__

XVThumbImagePlugin.__version__

IptcImagePlugin.__version__

PixarImagePlugin.__version__

Pyqt4和Pyside#

自 6.0.0 版本弃用.

Removed in version 7.0.0.

qt 4在2015-12-19达到了寿命终止。它的python绑定也是eol:pyqt4(自2018-08-31)和pyside(自2015-10-14)。

PyQt4和PySide的支持已从 ImageQt . 请升级到PyQt5或PySide2。

设置TIFF图像的大小#

自 5.3.0 版本弃用.

Removed in version 7.0.0.

直接设置TIFF图像的大小(例如。 im.size = (256, 256) )抛出错误。使用 Image.resize 相反。

版本常量#

自 5.2.0 版本弃用.

Removed in version 6.0.0.

VERSION (旧PIL版本,始终为1.1.7)已删除。使用 __version__ 相反。

未记录的ImageOps函数#

自 4.3.0 版本弃用.

Removed in version 6.0.0.

ImageOps 已被删除。使用等价物 ImageFilter 而是:

远离的

代替使用

ImageOps.box_blur

ImageFilter.BoxBlur

ImageOps.gaussian_blur

ImageFilter.GaussianBlur

ImageOps.gblur

ImageFilter.GaussianBlur

ImageOps.usm

ImageFilter.UnsharpMask

ImageOps.unsharp_mask

ImageFilter.UnsharpMask

PIL.OleFileIO#

自 4.0.0 版本弃用.

Removed in version 6.0.0.

在Pillow 4.0.0(2017-01)中,PIL.OleFileIO作为供应商文件被删除,取而代之的是上游olefile Python包,取而代之的是 ImportError 5.0.0(2018-01年度)。不推荐使用的文件现在已从枕头中删除。如果需要,请从PyPI安装(例如 python3 -m pip install olefile )。