9.2.0#

Deprecations#

PyQt5 and PySide2#

Deprecated since version 9.2.0.

Qt 5 reached end-of-life on 2020-12-08 for open-source users (and will reach EOL on 2023-12-08 for commercial licence holders).

Support for PyQt5 and PySide2 has been deprecated from ImageQt and will be removed in Pillow 10 (2023-07-01). Upgrade to PyQt6 or PySide6 instead.

FreeTypeFont.getmask2 fill parameter#

Deprecated since version 9.2.0.

The undocumented fill parameter of FreeTypeFont.getmask2() has been deprecated and will be removed in Pillow 10 (2023-07-01).

PhotoImage.paste box parameter#

Deprecated since version 9.2.0.

The box parameter is unused. It will be removed in Pillow 10.0.0 (2023-07-01).

Image.coerce_e#

Deprecated since version 9.2.0.

This undocumented method has been deprecated and will be removed in Pillow 10 (2023-07-01).

Font size and offset methods#

Deprecated since version 9.2.0.

Several functions for computing the size and offset of rendered text have been deprecated and will be removed in Pillow 10 (2023-07-01):

Deprecated

Use instead

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

Previous code:

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")

Use instead:

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

API Additions#

Image.apply_transparency#

Added apply_transparency(), a method to take a P mode image with “transparency” in im.info, and apply the transparency to the palette instead. The image’s palette mode will become “RGBA”, and “transparency” will be removed from im.info.

Security#

An additional decompression bomb check has been added for the GIF format.

Other Changes#

Using gnome-screenshot on Linux#

In grab() on Linux, if xdisplay is None then gnome-screenshot will be used to capture the display if it is installed. To capture the default X11 display instead, pass xdisplay="".