2010-07-31 06:52:47 +04:00
|
|
|
#
|
|
|
|
# The Python Imaging Library.
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# PIL raster font management
|
|
|
|
#
|
|
|
|
# History:
|
|
|
|
# 1996-08-07 fl created (experimental)
|
|
|
|
# 1997-08-25 fl minor adjustments to handle fonts from pilfont 0.3
|
|
|
|
# 1999-02-06 fl rewrote most font management stuff in C
|
|
|
|
# 1999-03-17 fl take pth files into account in load_path (from Richard Jones)
|
|
|
|
# 2001-02-17 fl added freetype support
|
|
|
|
# 2001-05-09 fl added TransposedFont wrapper class
|
|
|
|
# 2002-03-04 fl make sure we have a "L" or "1" font
|
|
|
|
# 2002-12-04 fl skip non-directory entries in the system path
|
|
|
|
# 2003-04-29 fl add embedded default font
|
|
|
|
# 2003-09-27 fl added support for truetype charmap encodings
|
|
|
|
#
|
|
|
|
# Todo:
|
|
|
|
# Adapt to PILFONT2 format (16-bit fonts, compressed, single file)
|
|
|
|
#
|
|
|
|
# Copyright (c) 1997-2003 by Secret Labs AB
|
|
|
|
# Copyright (c) 1996-2003 by Fredrik Lundh
|
|
|
|
#
|
|
|
|
# See the README file for information on usage and redistribution.
|
|
|
|
#
|
|
|
|
|
2019-10-07 16:28:36 +03:00
|
|
|
import base64
|
2014-07-05 02:02:46 +04:00
|
|
|
import os
|
|
|
|
import sys
|
2022-01-15 02:07:07 +03:00
|
|
|
import warnings
|
2022-01-15 01:02:31 +03:00
|
|
|
from enum import IntEnum
|
2019-10-07 16:28:36 +03:00
|
|
|
from io import BytesIO
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2021-10-17 23:29:41 +03:00
|
|
|
from . import Image
|
2022-04-05 16:33:20 +03:00
|
|
|
from ._deprecate import deprecate
|
2022-04-10 21:20:48 +03:00
|
|
|
from ._util import is_directory, is_path
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
|
|
|
|
class Layout(IntEnum):
|
|
|
|
BASIC = 0
|
|
|
|
RAQM = 1
|
|
|
|
|
|
|
|
|
2022-01-15 02:07:07 +03:00
|
|
|
def __getattr__(name):
|
|
|
|
for enum, prefix in {Layout: "LAYOUT_"}.items():
|
|
|
|
if name.startswith(prefix):
|
|
|
|
name = name[len(prefix) :]
|
|
|
|
if name in enum.__members__:
|
2022-04-05 16:33:20 +03:00
|
|
|
deprecate(f"{prefix}{name}", 10, f"{enum.__name__}.{name}")
|
2022-01-15 02:07:07 +03:00
|
|
|
return enum[name]
|
|
|
|
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
2014-07-05 02:02:46 +04:00
|
|
|
|
2018-03-03 12:54:00 +03:00
|
|
|
|
2022-04-10 21:21:50 +03:00
|
|
|
class _ImagingFtNotInstalled:
|
2010-07-31 06:52:47 +04:00
|
|
|
# module placeholder
|
|
|
|
def __getattr__(self, id):
|
|
|
|
raise ImportError("The _imagingft C module is not installed")
|
|
|
|
|
2017-07-23 23:58:05 +03:00
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
try:
|
2017-01-17 16:22:18 +03:00
|
|
|
from . import _imagingft as core
|
2010-07-31 06:52:47 +04:00
|
|
|
except ImportError:
|
2022-04-10 21:21:50 +03:00
|
|
|
core = _ImagingFtNotInstalled()
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2017-06-13 19:03:23 +03:00
|
|
|
|
2022-04-16 18:46:43 +03:00
|
|
|
_UNSPECIFIED = object()
|
|
|
|
|
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
# FIXME: add support for pilfont2 format (see FontFile.py)
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# Font metrics format:
|
|
|
|
# "PILfont" LF
|
|
|
|
# fontdescriptor LF
|
|
|
|
# (optional) key=value... LF
|
|
|
|
# "DATA" LF
|
|
|
|
# binary data: 256*10*2 bytes (dx, dy, dstbox, srcbox)
|
|
|
|
#
|
|
|
|
# To place a character, cut out srcbox and paste at dstbox,
|
|
|
|
# relative to the character position. Then move the character
|
|
|
|
# position according to dx, dy.
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2019-09-30 17:56:31 +03:00
|
|
|
class ImageFont:
|
2022-04-10 17:47:32 +03:00
|
|
|
"""PIL font wrapper"""
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
def _load_pilfont(self, filename):
|
|
|
|
|
2016-11-17 17:21:50 +03:00
|
|
|
with open(filename, "rb") as fp:
|
2020-02-18 12:49:05 +03:00
|
|
|
image = None
|
2016-11-17 17:21:50 +03:00
|
|
|
for ext in (".png", ".gif", ".pbm"):
|
2020-02-18 12:49:05 +03:00
|
|
|
if image:
|
|
|
|
image.close()
|
2016-11-17 17:21:50 +03:00
|
|
|
try:
|
|
|
|
fullname = os.path.splitext(filename)[0] + ext
|
|
|
|
image = Image.open(fullname)
|
2018-11-17 00:51:52 +03:00
|
|
|
except Exception:
|
2016-11-17 17:21:50 +03:00
|
|
|
pass
|
|
|
|
else:
|
|
|
|
if image and image.mode in ("1", "L"):
|
|
|
|
break
|
2010-07-31 06:52:47 +04:00
|
|
|
else:
|
2020-02-18 12:49:05 +03:00
|
|
|
if image:
|
|
|
|
image.close()
|
2019-09-30 17:56:31 +03:00
|
|
|
raise OSError("cannot find glyph data file")
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2016-11-17 17:21:50 +03:00
|
|
|
self.file = fullname
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2020-02-18 12:49:05 +03:00
|
|
|
self._load_pilfont_data(fp, image)
|
|
|
|
image.close()
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
def _load_pilfont_data(self, file, image):
|
|
|
|
|
|
|
|
# read PILfont header
|
py3k: The big push
There are two main issues fixed with this commit:
* bytes vs. str: All file, image, and palette data are now handled as
bytes. A new _binary module consolidates the hacks needed to do this
across Python versions. tostring/fromstring methods have been renamed to
tobytes/frombytes, but the Python 2.6/2.7 versions alias them to the old
names for compatibility. Users should move to tobytes/frombytes.
One other potentially-breaking change is that text data in image files
(such as tags, comments) are now explicitly handled with a specific
character encoding in mind. This works well with the Unicode str in
Python 3, but may trip up old code expecting a straight byte-for-byte
translation to a Python string. This also required a change to Gohlke's
tags tests (in Tests/test_file_png.py) to expect Unicode strings from
the code.
* True div vs. floor div: Many division operations used the "/" operator
to do floor division, which is now the "//" operator in Python 3. These
were fixed.
As of this commit, on the first pass, I have one failing test (improper
handling of a slice object in a C module, test_imagepath.py) in Python 3,
and three that that I haven't tried running yet (test_imagegl,
test_imagegrab, and test_imageqt). I also haven't tested anything on
Windows. All but the three skipped tests run flawlessly against Pythons
2.6 and 2.7.
2012-10-21 01:01:53 +04:00
|
|
|
if file.readline() != b"PILfont\n":
|
2010-07-31 06:52:47 +04:00
|
|
|
raise SyntaxError("Not a PILfont file")
|
2014-07-05 02:02:46 +04:00
|
|
|
file.readline().split(b";")
|
|
|
|
self.info = [] # FIXME: should be a dictionary
|
2010-07-31 06:52:47 +04:00
|
|
|
while True:
|
|
|
|
s = file.readline()
|
py3k: The big push
There are two main issues fixed with this commit:
* bytes vs. str: All file, image, and palette data are now handled as
bytes. A new _binary module consolidates the hacks needed to do this
across Python versions. tostring/fromstring methods have been renamed to
tobytes/frombytes, but the Python 2.6/2.7 versions alias them to the old
names for compatibility. Users should move to tobytes/frombytes.
One other potentially-breaking change is that text data in image files
(such as tags, comments) are now explicitly handled with a specific
character encoding in mind. This works well with the Unicode str in
Python 3, but may trip up old code expecting a straight byte-for-byte
translation to a Python string. This also required a change to Gohlke's
tags tests (in Tests/test_file_png.py) to expect Unicode strings from
the code.
* True div vs. floor div: Many division operations used the "/" operator
to do floor division, which is now the "//" operator in Python 3. These
were fixed.
As of this commit, on the first pass, I have one failing test (improper
handling of a slice object in a C module, test_imagepath.py) in Python 3,
and three that that I haven't tried running yet (test_imagegl,
test_imagegrab, and test_imageqt). I also haven't tested anything on
Windows. All but the three skipped tests run flawlessly against Pythons
2.6 and 2.7.
2012-10-21 01:01:53 +04:00
|
|
|
if not s or s == b"DATA\n":
|
2010-07-31 06:52:47 +04:00
|
|
|
break
|
|
|
|
self.info.append(s)
|
|
|
|
|
|
|
|
# read PILfont metrics
|
2019-03-21 16:28:20 +03:00
|
|
|
data = file.read(256 * 20)
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
# check image
|
|
|
|
if image.mode not in ("1", "L"):
|
|
|
|
raise TypeError("invalid font image mode")
|
|
|
|
|
|
|
|
image.load()
|
|
|
|
|
|
|
|
self.font = Image.core.font(image.im, data)
|
|
|
|
|
2017-06-29 17:01:38 +03:00
|
|
|
def getsize(self, text, *args, **kwargs):
|
2019-07-07 13:52:30 +03:00
|
|
|
"""
|
2022-06-30 15:40:40 +03:00
|
|
|
.. deprecated:: 9.2.0
|
2022-07-01 12:45:36 +03:00
|
|
|
|
|
|
|
Use :py:meth:`.getbbox` or :py:meth:`.getlength` instead.
|
2022-06-30 15:40:40 +03:00
|
|
|
|
2019-07-07 13:52:30 +03:00
|
|
|
Returns width and height (in pixels) of given text.
|
|
|
|
|
|
|
|
:param text: Text to measure.
|
|
|
|
|
|
|
|
:return: (width, height)
|
|
|
|
"""
|
2022-07-01 13:33:59 +03:00
|
|
|
deprecate("getsize", 10, "getbbox or getlength")
|
2017-06-29 17:01:38 +03:00
|
|
|
return self.font.getsize(text)
|
|
|
|
|
|
|
|
def getmask(self, text, mode="", *args, **kwargs):
|
2019-07-07 13:52:30 +03:00
|
|
|
"""
|
|
|
|
Create a bitmap for the text.
|
|
|
|
|
|
|
|
If the font uses antialiasing, the bitmap should have mode ``L`` and use a
|
|
|
|
maximum value of 255. Otherwise, it should have mode ``1``.
|
|
|
|
|
|
|
|
:param text: Text to render.
|
|
|
|
:param mode: Used by some graphics drivers to indicate what mode the
|
|
|
|
driver prefers; if empty, the renderer may return either
|
|
|
|
mode. Note that the mode is always a string, to simplify
|
|
|
|
C-level implementations.
|
|
|
|
|
|
|
|
.. versionadded:: 1.1.5
|
|
|
|
|
|
|
|
:return: An internal PIL storage memory instance as defined by the
|
|
|
|
:py:mod:`PIL.Image.core` interface module.
|
|
|
|
"""
|
2017-06-29 17:01:38 +03:00
|
|
|
return self.font.getmask(text, mode)
|
|
|
|
|
2022-05-25 20:06:20 +03:00
|
|
|
def getbbox(self, text, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Returns bounding box (in pixels) of given text.
|
|
|
|
|
|
|
|
.. versionadded:: 9.2.0
|
|
|
|
|
|
|
|
:param text: Text to render.
|
|
|
|
:param mode: Used by some graphics drivers to indicate what mode the
|
|
|
|
driver prefers; if empty, the renderer may return either
|
|
|
|
mode. Note that the mode is always a string, to simplify
|
|
|
|
C-level implementations.
|
|
|
|
|
|
|
|
:return: ``(left, top, right, bottom)`` bounding box
|
|
|
|
"""
|
|
|
|
width, height = self.font.getsize(text)
|
|
|
|
return 0, 0, width, height
|
|
|
|
|
|
|
|
def getlength(self, text, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Returns length (in pixels) of given text.
|
|
|
|
This is the amount by which following text should be offset.
|
|
|
|
|
|
|
|
.. versionadded:: 9.2.0
|
|
|
|
"""
|
|
|
|
width, height = self.font.getsize(text)
|
|
|
|
return width
|
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
##
|
|
|
|
# Wrapper for FreeType fonts. Application code should use the
|
|
|
|
# <b>truetype</b> factory function to create font objects.
|
|
|
|
|
2019-03-21 16:28:20 +03:00
|
|
|
|
2019-09-30 17:56:31 +03:00
|
|
|
class FreeTypeFont:
|
2022-04-10 17:47:32 +03:00
|
|
|
"""FreeType font wrapper (requires _imagingft service)"""
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2019-03-21 16:28:20 +03:00
|
|
|
def __init__(self, font=None, size=10, index=0, encoding="", layout_engine=None):
|
2010-07-31 06:52:47 +04:00
|
|
|
# FIXME: use service provider instead
|
2013-04-25 20:48:43 +04:00
|
|
|
|
2015-03-03 16:00:18 +03:00
|
|
|
self.path = font
|
|
|
|
self.size = size
|
|
|
|
self.index = index
|
|
|
|
self.encoding = encoding
|
|
|
|
|
2022-01-15 01:02:31 +03:00
|
|
|
if layout_engine not in (Layout.BASIC, Layout.RAQM):
|
|
|
|
layout_engine = Layout.BASIC
|
2017-06-13 19:03:23 +03:00
|
|
|
if core.HAVE_RAQM:
|
2022-01-15 01:02:31 +03:00
|
|
|
layout_engine = Layout.RAQM
|
|
|
|
elif layout_engine == Layout.RAQM and not core.HAVE_RAQM:
|
2022-02-08 02:57:35 +03:00
|
|
|
warnings.warn(
|
|
|
|
"Raqm layout was requested, but Raqm is not available. "
|
|
|
|
"Falling back to basic layout."
|
|
|
|
)
|
2022-01-15 01:02:31 +03:00
|
|
|
layout_engine = Layout.BASIC
|
2017-06-13 19:03:23 +03:00
|
|
|
|
|
|
|
self.layout_engine = layout_engine
|
|
|
|
|
2019-04-07 17:27:16 +03:00
|
|
|
def load_from_bytes(f):
|
|
|
|
self.font_bytes = f.read()
|
|
|
|
self.font = core.getfont(
|
2019-06-11 11:42:05 +03:00
|
|
|
"", size, index, encoding, self.font_bytes, layout_engine
|
|
|
|
)
|
2019-04-07 17:27:16 +03:00
|
|
|
|
2022-04-10 21:20:48 +03:00
|
|
|
if is_path(font):
|
2019-04-07 17:27:16 +03:00
|
|
|
if sys.platform == "win32":
|
|
|
|
font_bytes_path = font if isinstance(font, bytes) else font.encode()
|
|
|
|
try:
|
2019-06-11 11:42:05 +03:00
|
|
|
font_bytes_path.decode("ascii")
|
2019-04-07 17:27:16 +03:00
|
|
|
except UnicodeDecodeError:
|
|
|
|
# FreeType cannot load fonts with non-ASCII characters on Windows
|
|
|
|
# So load it into memory first
|
2019-06-11 11:42:05 +03:00
|
|
|
with open(font, "rb") as f:
|
2019-04-07 17:27:16 +03:00
|
|
|
load_from_bytes(f)
|
|
|
|
return
|
2019-06-11 11:42:05 +03:00
|
|
|
self.font = core.getfont(
|
|
|
|
font, size, index, encoding, layout_engine=layout_engine
|
|
|
|
)
|
2013-04-25 20:48:43 +04:00
|
|
|
else:
|
2019-04-07 17:27:16 +03:00
|
|
|
load_from_bytes(font)
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2021-11-10 15:34:20 +03:00
|
|
|
def __getstate__(self):
|
|
|
|
return [self.path, self.size, self.index, self.encoding, self.layout_engine]
|
|
|
|
|
|
|
|
def __setstate__(self, state):
|
|
|
|
path, size, index, encoding, layout_engine = state
|
|
|
|
self.__init__(path, size, index, encoding, layout_engine)
|
|
|
|
|
2018-04-24 17:15:16 +03:00
|
|
|
def _multiline_split(self, text):
|
|
|
|
split_character = "\n" if isinstance(text, str) else b"\n"
|
|
|
|
return text.split(split_character)
|
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
def getname(self):
|
2019-04-21 16:27:31 +03:00
|
|
|
"""
|
|
|
|
:return: A tuple of the font family (e.g. Helvetica) and the font style
|
|
|
|
(e.g. Bold)
|
|
|
|
"""
|
2010-07-31 06:52:47 +04:00
|
|
|
return self.font.family, self.font.style
|
|
|
|
|
|
|
|
def getmetrics(self):
|
2019-04-21 16:27:31 +03:00
|
|
|
"""
|
|
|
|
:return: A tuple of the font ascent (the distance from the baseline to
|
|
|
|
the highest outline point) and descent (the distance from the
|
|
|
|
baseline to the lowest outline point, a negative value)
|
|
|
|
"""
|
2010-07-31 06:52:47 +04:00
|
|
|
return self.font.ascent, self.font.descent
|
|
|
|
|
2020-06-20 13:54:53 +03:00
|
|
|
def getlength(self, text, mode="", direction=None, features=None, language=None):
|
|
|
|
"""
|
2020-10-11 22:55:32 +03:00
|
|
|
Returns length (in pixels with 1/64 precision) of given text when rendered
|
2020-06-20 13:54:53 +03:00
|
|
|
in font with provided direction, features, and language.
|
|
|
|
|
|
|
|
This is the amount by which following text should be offset.
|
|
|
|
Text bounding box may extend past the length in some fonts,
|
|
|
|
e.g. when using italics or accents.
|
|
|
|
|
|
|
|
The result is returned as a float; it is a whole number if using basic layout.
|
|
|
|
|
|
|
|
Note that the sum of two lengths may not equal the length of a concatenated
|
|
|
|
string due to kerning. If you need to adjust for kerning, include the following
|
|
|
|
character and subtract its length.
|
|
|
|
|
|
|
|
For example, instead of
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
hello = font.getlength("Hello")
|
|
|
|
world = font.getlength("World")
|
|
|
|
hello_world = hello + world # not adjusted for kerning
|
|
|
|
assert hello_world == font.getlength("HelloWorld") # may fail
|
|
|
|
|
|
|
|
use
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
hello = font.getlength("HelloW") - font.getlength("W") # adjusted for kerning
|
|
|
|
world = font.getlength("World")
|
|
|
|
hello_world = hello + world # adjusted for kerning
|
|
|
|
assert hello_world == font.getlength("HelloWorld") # True
|
|
|
|
|
2020-10-08 22:30:39 +03:00
|
|
|
or disable kerning with (requires libraqm)
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
hello = draw.textlength("Hello", font, features=["-kern"])
|
|
|
|
world = draw.textlength("World", font, features=["-kern"])
|
|
|
|
hello_world = hello + world # kerning is disabled, no need to adjust
|
|
|
|
assert hello_world == draw.textlength("HelloWorld", font, features=["-kern"])
|
|
|
|
|
2020-06-20 13:54:53 +03:00
|
|
|
.. versionadded:: 8.0.0
|
|
|
|
|
|
|
|
:param text: Text to measure.
|
|
|
|
:param mode: Used by some graphics drivers to indicate what mode the
|
|
|
|
driver prefers; if empty, the renderer may return either
|
|
|
|
mode. Note that the mode is always a string, to simplify
|
|
|
|
C-level implementations.
|
|
|
|
|
|
|
|
:param direction: Direction of the text. It can be 'rtl' (right to
|
|
|
|
left), 'ltr' (left to right) or 'ttb' (top to bottom).
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
:param features: A list of OpenType font features to be used during text
|
|
|
|
layout. This is usually used to turn on optional
|
|
|
|
font features that are not enabled by default,
|
|
|
|
for example 'dlig' or 'ss01', but can be also
|
|
|
|
used to turn off default font features for
|
|
|
|
example '-liga' to disable ligatures or '-kern'
|
|
|
|
to disable kerning. To get all supported
|
|
|
|
features, see
|
|
|
|
https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
:param language: Language of the text. Different languages may use
|
|
|
|
different glyph shapes or ligatures. This parameter tells
|
|
|
|
the font which language the text is in, and to apply the
|
|
|
|
correct substitutions as appropriate, if available.
|
|
|
|
It should be a `BCP 47 language code
|
2020-11-14 00:41:44 +03:00
|
|
|
<https://www.w3.org/International/articles/language-tags/>`_
|
2020-06-20 13:54:53 +03:00
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
:return: Width for horizontal, height for vertical text.
|
|
|
|
"""
|
2020-10-12 18:05:19 +03:00
|
|
|
return self.font.getlength(text, mode, direction, features, language) / 64
|
2020-06-20 13:54:53 +03:00
|
|
|
|
|
|
|
def getbbox(
|
|
|
|
self,
|
|
|
|
text,
|
|
|
|
mode="",
|
|
|
|
direction=None,
|
|
|
|
features=None,
|
|
|
|
language=None,
|
|
|
|
stroke_width=0,
|
|
|
|
anchor=None,
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Returns bounding box (in pixels) of given text relative to given anchor
|
2020-10-11 22:55:32 +03:00
|
|
|
when rendered in font with provided direction, features, and language.
|
2020-06-20 13:54:53 +03:00
|
|
|
|
2020-10-09 17:43:10 +03:00
|
|
|
Use :py:meth:`getlength()` to get the offset of following text with
|
2020-06-20 13:54:53 +03:00
|
|
|
1/64 pixel precision. The bounding box includes extra margins for
|
|
|
|
some fonts, e.g. italics or accents.
|
|
|
|
|
|
|
|
.. versionadded:: 8.0.0
|
|
|
|
|
|
|
|
:param text: Text to render.
|
|
|
|
:param mode: Used by some graphics drivers to indicate what mode the
|
|
|
|
driver prefers; if empty, the renderer may return either
|
|
|
|
mode. Note that the mode is always a string, to simplify
|
|
|
|
C-level implementations.
|
|
|
|
|
|
|
|
:param direction: Direction of the text. It can be 'rtl' (right to
|
|
|
|
left), 'ltr' (left to right) or 'ttb' (top to bottom).
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
:param features: A list of OpenType font features to be used during text
|
|
|
|
layout. This is usually used to turn on optional
|
|
|
|
font features that are not enabled by default,
|
|
|
|
for example 'dlig' or 'ss01', but can be also
|
|
|
|
used to turn off default font features for
|
|
|
|
example '-liga' to disable ligatures or '-kern'
|
|
|
|
to disable kerning. To get all supported
|
|
|
|
features, see
|
|
|
|
https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
:param language: Language of the text. Different languages may use
|
|
|
|
different glyph shapes or ligatures. This parameter tells
|
|
|
|
the font which language the text is in, and to apply the
|
|
|
|
correct substitutions as appropriate, if available.
|
|
|
|
It should be a `BCP 47 language code
|
2020-11-14 00:41:44 +03:00
|
|
|
<https://www.w3.org/International/articles/language-tags/>`_
|
2020-06-20 13:54:53 +03:00
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
:param stroke_width: The width of the text stroke.
|
|
|
|
|
|
|
|
:param anchor: The text anchor alignment. Determines the relative location of
|
|
|
|
the anchor to the text. The default alignment is top left.
|
|
|
|
See :ref:`text-anchors` for valid values.
|
|
|
|
|
|
|
|
:return: ``(left, top, right, bottom)`` bounding box
|
|
|
|
"""
|
|
|
|
size, offset = self.font.getsize(
|
2020-10-12 18:05:19 +03:00
|
|
|
text, mode, direction, features, language, anchor
|
2020-06-20 13:54:53 +03:00
|
|
|
)
|
|
|
|
left, top = offset[0] - stroke_width, offset[1] - stroke_width
|
|
|
|
width, height = size[0] + 2 * stroke_width, size[1] + 2 * stroke_width
|
|
|
|
return left, top, left + width, top + height
|
|
|
|
|
2019-07-28 23:40:03 +03:00
|
|
|
def getsize(
|
2022-05-25 03:57:13 +03:00
|
|
|
self,
|
|
|
|
text,
|
|
|
|
direction=None,
|
|
|
|
features=None,
|
|
|
|
language=None,
|
|
|
|
stroke_width=0,
|
2019-07-28 23:40:03 +03:00
|
|
|
):
|
2019-04-21 16:27:31 +03:00
|
|
|
"""
|
2022-06-30 15:40:40 +03:00
|
|
|
.. deprecated:: 9.2.0
|
2022-07-01 12:45:36 +03:00
|
|
|
|
|
|
|
Use :py:meth:`getlength()` to measure the offset of following text with
|
|
|
|
1/64 pixel precision.
|
|
|
|
Use :py:meth:`getbbox()` to get the exact bounding box based on an anchor.
|
2022-06-30 15:40:40 +03:00
|
|
|
|
2019-04-21 16:27:31 +03:00
|
|
|
Returns width and height (in pixels) of given text if rendered in font with
|
|
|
|
provided direction, features, and language.
|
|
|
|
|
2020-06-20 13:54:53 +03:00
|
|
|
.. note:: For historical reasons this function measures text height from
|
|
|
|
the ascender line instead of the top, see :ref:`text-anchors`.
|
|
|
|
If you wish to measure text height from the top, it is recommended
|
|
|
|
to use the bottom value of :meth:`getbbox` with ``anchor='lt'`` instead.
|
|
|
|
|
2019-04-21 16:27:31 +03:00
|
|
|
:param text: Text to measure.
|
|
|
|
|
|
|
|
:param direction: Direction of the text. It can be 'rtl' (right to
|
|
|
|
left), 'ltr' (left to right) or 'ttb' (top to bottom).
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
.. versionadded:: 4.2.0
|
|
|
|
|
|
|
|
:param features: A list of OpenType font features to be used during text
|
|
|
|
layout. This is usually used to turn on optional
|
|
|
|
font features that are not enabled by default,
|
|
|
|
for example 'dlig' or 'ss01', but can be also
|
|
|
|
used to turn off default font features for
|
|
|
|
example '-liga' to disable ligatures or '-kern'
|
|
|
|
to disable kerning. To get all supported
|
|
|
|
features, see
|
|
|
|
https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
.. versionadded:: 4.2.0
|
|
|
|
|
|
|
|
:param language: Language of the text. Different languages may use
|
|
|
|
different glyph shapes or ligatures. This parameter tells
|
|
|
|
the font which language the text is in, and to apply the
|
|
|
|
correct substitutions as appropriate, if available.
|
2019-04-23 23:16:15 +03:00
|
|
|
It should be a `BCP 47 language code
|
2020-11-14 00:41:44 +03:00
|
|
|
<https://www.w3.org/International/articles/language-tags/>`_
|
2019-04-21 16:27:31 +03:00
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
.. versionadded:: 6.0.0
|
|
|
|
|
2019-07-28 23:40:03 +03:00
|
|
|
:param stroke_width: The width of the text stroke.
|
|
|
|
|
|
|
|
.. versionadded:: 6.2.0
|
|
|
|
|
2019-04-21 16:27:31 +03:00
|
|
|
:return: (width, height)
|
|
|
|
"""
|
2022-07-01 13:33:59 +03:00
|
|
|
deprecate("getsize", 10, "getbbox or getlength")
|
2020-09-11 02:14:00 +03:00
|
|
|
# vertical offset is added for historical reasons
|
|
|
|
# see https://github.com/python-pillow/Pillow/pull/4910#discussion_r486682929
|
2020-03-28 07:58:35 +03:00
|
|
|
size, offset = self.font.getsize(text, "L", direction, features, language)
|
2019-07-28 23:40:03 +03:00
|
|
|
return (
|
2020-09-02 00:29:06 +03:00
|
|
|
size[0] + stroke_width * 2,
|
2019-07-28 23:40:03 +03:00
|
|
|
size[1] + stroke_width * 2 + offset[1],
|
|
|
|
)
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2019-06-11 11:42:05 +03:00
|
|
|
def getsize_multiline(
|
2019-07-28 23:40:03 +03:00
|
|
|
self,
|
|
|
|
text,
|
|
|
|
direction=None,
|
|
|
|
spacing=4,
|
|
|
|
features=None,
|
|
|
|
language=None,
|
|
|
|
stroke_width=0,
|
2019-06-11 11:42:05 +03:00
|
|
|
):
|
2019-04-21 16:27:31 +03:00
|
|
|
"""
|
2022-06-30 15:40:40 +03:00
|
|
|
.. deprecated:: 9.2.0
|
2022-07-01 12:45:36 +03:00
|
|
|
|
|
|
|
Use :py:meth:`.ImageDraw.multiline_textbbox` instead.
|
2022-06-30 15:40:40 +03:00
|
|
|
|
2019-04-21 16:27:31 +03:00
|
|
|
Returns width and height (in pixels) of given text if rendered in font
|
|
|
|
with provided direction, features, and language, while respecting
|
|
|
|
newline characters.
|
|
|
|
|
|
|
|
:param text: Text to measure.
|
|
|
|
|
|
|
|
:param direction: Direction of the text. It can be 'rtl' (right to
|
|
|
|
left), 'ltr' (left to right) or 'ttb' (top to bottom).
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
:param spacing: The vertical gap between lines, defaulting to 4 pixels.
|
|
|
|
|
|
|
|
:param features: A list of OpenType font features to be used during text
|
|
|
|
layout. This is usually used to turn on optional
|
|
|
|
font features that are not enabled by default,
|
|
|
|
for example 'dlig' or 'ss01', but can be also
|
|
|
|
used to turn off default font features for
|
|
|
|
example '-liga' to disable ligatures or '-kern'
|
|
|
|
to disable kerning. To get all supported
|
|
|
|
features, see
|
|
|
|
https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
:param language: Language of the text. Different languages may use
|
|
|
|
different glyph shapes or ligatures. This parameter tells
|
|
|
|
the font which language the text is in, and to apply the
|
|
|
|
correct substitutions as appropriate, if available.
|
2019-04-23 23:16:15 +03:00
|
|
|
It should be a `BCP 47 language code
|
2020-11-14 00:41:44 +03:00
|
|
|
<https://www.w3.org/International/articles/language-tags/>`_
|
2019-04-21 16:27:31 +03:00
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
.. versionadded:: 6.0.0
|
|
|
|
|
2019-07-28 23:40:03 +03:00
|
|
|
:param stroke_width: The width of the text stroke.
|
|
|
|
|
|
|
|
.. versionadded:: 6.2.0
|
|
|
|
|
2019-04-21 16:27:31 +03:00
|
|
|
:return: (width, height)
|
|
|
|
"""
|
2022-06-30 15:22:07 +03:00
|
|
|
deprecate("getsize_multiline", 10, "ImageDraw.multiline_textbbox")
|
2018-04-24 17:15:16 +03:00
|
|
|
max_width = 0
|
|
|
|
lines = self._multiline_split(text)
|
2022-07-01 13:33:59 +03:00
|
|
|
with warnings.catch_warnings():
|
|
|
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
|
|
line_spacing = self.getsize("A", stroke_width=stroke_width)[1] + spacing
|
|
|
|
for line in lines:
|
|
|
|
line_width, line_height = self.getsize(
|
|
|
|
line, direction, features, language, stroke_width
|
|
|
|
)
|
|
|
|
max_width = max(max_width, line_width)
|
2018-04-24 17:15:16 +03:00
|
|
|
|
2019-03-21 16:28:20 +03:00
|
|
|
return max_width, len(lines) * line_spacing - spacing
|
2018-04-24 17:15:16 +03:00
|
|
|
|
2013-09-20 17:02:40 +04:00
|
|
|
def getoffset(self, text):
|
2019-04-21 16:27:31 +03:00
|
|
|
"""
|
2022-06-30 15:40:40 +03:00
|
|
|
.. deprecated:: 9.2.0
|
2022-07-01 12:45:36 +03:00
|
|
|
|
|
|
|
Use :py:meth:`.getbbox` instead.
|
2022-06-30 15:40:40 +03:00
|
|
|
|
2019-04-21 16:27:31 +03:00
|
|
|
Returns the offset of given text. This is the gap between the
|
|
|
|
starting coordinate and the first marking. Note that this gap is
|
|
|
|
included in the result of :py:func:`~PIL.ImageFont.FreeTypeFont.getsize`.
|
|
|
|
|
|
|
|
:param text: Text to measure.
|
|
|
|
|
|
|
|
:return: A tuple of the x and y offset
|
|
|
|
"""
|
2022-05-25 03:57:13 +03:00
|
|
|
deprecate("getoffset", 10, "getbbox")
|
2013-09-20 17:02:40 +04:00
|
|
|
return self.font.getsize(text)[1]
|
|
|
|
|
2019-07-28 23:40:03 +03:00
|
|
|
def getmask(
|
|
|
|
self,
|
|
|
|
text,
|
|
|
|
mode="",
|
|
|
|
direction=None,
|
|
|
|
features=None,
|
|
|
|
language=None,
|
|
|
|
stroke_width=0,
|
2020-04-14 14:28:09 +03:00
|
|
|
anchor=None,
|
2020-03-28 07:58:35 +03:00
|
|
|
ink=0,
|
2019-07-28 23:40:03 +03:00
|
|
|
):
|
2019-04-21 16:27:31 +03:00
|
|
|
"""
|
|
|
|
Create a bitmap for the text.
|
|
|
|
|
2019-05-22 10:12:13 +03:00
|
|
|
If the font uses antialiasing, the bitmap should have mode ``L`` and use a
|
2020-03-28 07:58:35 +03:00
|
|
|
maximum value of 255. If the font has embedded color data, the bitmap
|
|
|
|
should have mode ``RGBA``. Otherwise, it should have mode ``1``.
|
2019-04-21 16:27:31 +03:00
|
|
|
|
|
|
|
:param text: Text to render.
|
|
|
|
:param mode: Used by some graphics drivers to indicate what mode the
|
|
|
|
driver prefers; if empty, the renderer may return either
|
|
|
|
mode. Note that the mode is always a string, to simplify
|
|
|
|
C-level implementations.
|
|
|
|
|
|
|
|
.. versionadded:: 1.1.5
|
|
|
|
|
|
|
|
:param direction: Direction of the text. It can be 'rtl' (right to
|
|
|
|
left), 'ltr' (left to right) or 'ttb' (top to bottom).
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
.. versionadded:: 4.2.0
|
|
|
|
|
|
|
|
:param features: A list of OpenType font features to be used during text
|
|
|
|
layout. This is usually used to turn on optional
|
|
|
|
font features that are not enabled by default,
|
|
|
|
for example 'dlig' or 'ss01', but can be also
|
|
|
|
used to turn off default font features for
|
|
|
|
example '-liga' to disable ligatures or '-kern'
|
|
|
|
to disable kerning. To get all supported
|
|
|
|
features, see
|
|
|
|
https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
.. versionadded:: 4.2.0
|
|
|
|
|
|
|
|
:param language: Language of the text. Different languages may use
|
|
|
|
different glyph shapes or ligatures. This parameter tells
|
|
|
|
the font which language the text is in, and to apply the
|
|
|
|
correct substitutions as appropriate, if available.
|
2019-04-23 23:16:15 +03:00
|
|
|
It should be a `BCP 47 language code
|
2020-11-14 00:41:44 +03:00
|
|
|
<https://www.w3.org/International/articles/language-tags/>`_
|
2019-04-21 16:27:31 +03:00
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
.. versionadded:: 6.0.0
|
|
|
|
|
2019-07-28 23:40:03 +03:00
|
|
|
:param stroke_width: The width of the text stroke.
|
|
|
|
|
|
|
|
.. versionadded:: 6.2.0
|
|
|
|
|
2020-04-14 14:28:09 +03:00
|
|
|
:param anchor: The text anchor alignment. Determines the relative location of
|
|
|
|
the anchor to the text. The default alignment is top left.
|
2020-04-23 06:38:41 +03:00
|
|
|
See :ref:`text-anchors` for valid values.
|
2020-04-14 14:28:09 +03:00
|
|
|
|
|
|
|
.. versionadded:: 8.0.0
|
|
|
|
|
2020-03-28 07:58:35 +03:00
|
|
|
:param ink: Foreground ink for rendering in RGBA mode.
|
|
|
|
|
|
|
|
.. versionadded:: 8.0.0
|
|
|
|
|
2019-04-21 16:27:31 +03:00
|
|
|
:return: An internal PIL storage memory instance as defined by the
|
|
|
|
:py:mod:`PIL.Image.core` interface module.
|
|
|
|
"""
|
2019-06-11 11:42:05 +03:00
|
|
|
return self.getmask2(
|
2019-07-28 23:40:03 +03:00
|
|
|
text,
|
|
|
|
mode,
|
|
|
|
direction=direction,
|
|
|
|
features=features,
|
|
|
|
language=language,
|
|
|
|
stroke_width=stroke_width,
|
2020-04-14 14:28:09 +03:00
|
|
|
anchor=anchor,
|
2020-03-28 07:58:35 +03:00
|
|
|
ink=ink,
|
2019-06-11 11:42:05 +03:00
|
|
|
)[0]
|
|
|
|
|
|
|
|
def getmask2(
|
|
|
|
self,
|
|
|
|
text,
|
|
|
|
mode="",
|
2022-04-16 18:46:43 +03:00
|
|
|
fill=_UNSPECIFIED,
|
2019-06-11 11:42:05 +03:00
|
|
|
direction=None,
|
|
|
|
features=None,
|
|
|
|
language=None,
|
2019-07-28 23:40:03 +03:00
|
|
|
stroke_width=0,
|
2020-04-14 14:28:09 +03:00
|
|
|
anchor=None,
|
2020-03-28 07:58:35 +03:00
|
|
|
ink=0,
|
2019-06-11 11:42:05 +03:00
|
|
|
*args,
|
2020-07-15 13:37:43 +03:00
|
|
|
**kwargs,
|
2019-06-11 11:42:05 +03:00
|
|
|
):
|
2019-04-21 16:27:31 +03:00
|
|
|
"""
|
|
|
|
Create a bitmap for the text.
|
|
|
|
|
2019-05-22 10:12:13 +03:00
|
|
|
If the font uses antialiasing, the bitmap should have mode ``L`` and use a
|
2020-03-28 07:58:35 +03:00
|
|
|
maximum value of 255. If the font has embedded color data, the bitmap
|
|
|
|
should have mode ``RGBA``. Otherwise, it should have mode ``1``.
|
2019-04-21 16:27:31 +03:00
|
|
|
|
|
|
|
:param text: Text to render.
|
|
|
|
:param mode: Used by some graphics drivers to indicate what mode the
|
|
|
|
driver prefers; if empty, the renderer may return either
|
|
|
|
mode. Note that the mode is always a string, to simplify
|
|
|
|
C-level implementations.
|
|
|
|
|
|
|
|
.. versionadded:: 1.1.5
|
|
|
|
|
2022-04-17 07:33:16 +03:00
|
|
|
:param fill: Optional fill function. By default, an internal Pillow function
|
|
|
|
will be used.
|
|
|
|
|
2022-04-17 07:33:27 +03:00
|
|
|
Deprecated. This parameter will be removed in Pillow 10
|
|
|
|
(2023-07-01).
|
2022-04-16 18:07:32 +03:00
|
|
|
|
2019-04-21 16:27:31 +03:00
|
|
|
:param direction: Direction of the text. It can be 'rtl' (right to
|
|
|
|
left), 'ltr' (left to right) or 'ttb' (top to bottom).
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
.. versionadded:: 4.2.0
|
|
|
|
|
|
|
|
:param features: A list of OpenType font features to be used during text
|
|
|
|
layout. This is usually used to turn on optional
|
|
|
|
font features that are not enabled by default,
|
|
|
|
for example 'dlig' or 'ss01', but can be also
|
|
|
|
used to turn off default font features for
|
|
|
|
example '-liga' to disable ligatures or '-kern'
|
|
|
|
to disable kerning. To get all supported
|
|
|
|
features, see
|
|
|
|
https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
|
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
.. versionadded:: 4.2.0
|
|
|
|
|
|
|
|
:param language: Language of the text. Different languages may use
|
|
|
|
different glyph shapes or ligatures. This parameter tells
|
|
|
|
the font which language the text is in, and to apply the
|
|
|
|
correct substitutions as appropriate, if available.
|
2019-04-23 23:16:15 +03:00
|
|
|
It should be a `BCP 47 language code
|
2020-11-14 00:41:44 +03:00
|
|
|
<https://www.w3.org/International/articles/language-tags/>`_
|
2019-04-21 16:27:31 +03:00
|
|
|
Requires libraqm.
|
|
|
|
|
|
|
|
.. versionadded:: 6.0.0
|
|
|
|
|
2019-07-28 23:40:03 +03:00
|
|
|
:param stroke_width: The width of the text stroke.
|
|
|
|
|
|
|
|
.. versionadded:: 6.2.0
|
|
|
|
|
2020-04-14 14:28:09 +03:00
|
|
|
:param anchor: The text anchor alignment. Determines the relative location of
|
|
|
|
the anchor to the text. The default alignment is top left.
|
2020-04-23 06:38:41 +03:00
|
|
|
See :ref:`text-anchors` for valid values.
|
2020-04-14 14:28:09 +03:00
|
|
|
|
|
|
|
.. versionadded:: 8.0.0
|
|
|
|
|
2020-03-28 07:58:35 +03:00
|
|
|
:param ink: Foreground ink for rendering in RGBA mode.
|
|
|
|
|
|
|
|
.. versionadded:: 8.0.0
|
|
|
|
|
2019-04-21 16:27:31 +03:00
|
|
|
:return: A tuple of an internal PIL storage memory instance as defined by the
|
|
|
|
:py:mod:`PIL.Image.core` interface module, and the text offset, the
|
|
|
|
gap between the starting coordinate and the first marking
|
|
|
|
"""
|
2022-04-17 20:27:14 +03:00
|
|
|
if fill is _UNSPECIFIED:
|
2022-04-16 18:07:32 +03:00
|
|
|
fill = Image.core.fill
|
2022-04-17 20:27:14 +03:00
|
|
|
else:
|
|
|
|
deprecate("fill", 10)
|
2020-05-28 00:21:32 +03:00
|
|
|
size, offset = self.font.getsize(
|
2020-03-28 07:58:35 +03:00
|
|
|
text, mode, direction, features, language, anchor
|
2020-05-28 00:21:32 +03:00
|
|
|
)
|
2019-07-28 23:40:03 +03:00
|
|
|
size = size[0] + stroke_width * 2, size[1] + stroke_width * 2
|
2020-04-14 14:28:09 +03:00
|
|
|
offset = offset[0] - stroke_width, offset[1] - stroke_width
|
2021-03-15 01:26:28 +03:00
|
|
|
Image._decompression_bomb_check(size)
|
2020-03-28 07:58:35 +03:00
|
|
|
im = fill("RGBA" if mode == "RGBA" else "L", size, 0)
|
2019-07-28 23:40:03 +03:00
|
|
|
self.font.render(
|
2020-03-28 07:58:35 +03:00
|
|
|
text, im.id, mode, direction, features, language, stroke_width, ink
|
2019-07-28 23:40:03 +03:00
|
|
|
)
|
2010-07-31 06:52:47 +04:00
|
|
|
return im, offset
|
|
|
|
|
2019-03-21 16:28:20 +03:00
|
|
|
def font_variant(
|
|
|
|
self, font=None, size=None, index=None, encoding=None, layout_engine=None
|
|
|
|
):
|
2015-03-21 11:32:26 +03:00
|
|
|
"""
|
|
|
|
Create a copy of this FreeTypeFont object,
|
|
|
|
using any specified arguments to override the settings.
|
|
|
|
|
|
|
|
Parameters are identical to the parameters used to initialize this
|
2015-07-13 10:39:34 +03:00
|
|
|
object.
|
2015-03-21 11:32:26 +03:00
|
|
|
|
|
|
|
:return: A FreeTypeFont object.
|
|
|
|
"""
|
2022-04-22 00:31:20 +03:00
|
|
|
if font is None:
|
|
|
|
try:
|
|
|
|
font = BytesIO(self.font_bytes)
|
|
|
|
except AttributeError:
|
|
|
|
font = self.path
|
2018-06-24 15:32:25 +03:00
|
|
|
return FreeTypeFont(
|
2022-04-22 00:31:20 +03:00
|
|
|
font=font,
|
2018-06-24 15:32:25 +03:00
|
|
|
size=self.size if size is None else size,
|
|
|
|
index=self.index if index is None else index,
|
|
|
|
encoding=self.encoding if encoding is None else encoding,
|
2019-03-21 16:28:20 +03:00
|
|
|
layout_engine=layout_engine or self.layout_engine,
|
2018-06-24 15:32:25 +03:00
|
|
|
)
|
2015-03-03 16:00:18 +03:00
|
|
|
|
2019-06-12 13:27:11 +03:00
|
|
|
def get_variation_names(self):
|
|
|
|
"""
|
|
|
|
:returns: A list of the named styles in a variation font.
|
2020-04-07 09:58:21 +03:00
|
|
|
:exception OSError: If the font is not a variation font.
|
2019-06-12 13:27:11 +03:00
|
|
|
"""
|
|
|
|
try:
|
|
|
|
names = self.font.getvarnames()
|
2020-06-21 13:13:35 +03:00
|
|
|
except AttributeError as e:
|
|
|
|
raise NotImplementedError("FreeType 2.9.1 or greater is required") from e
|
2019-06-12 13:27:11 +03:00
|
|
|
return [name.replace(b"\x00", b"") for name in names]
|
|
|
|
|
|
|
|
def set_variation_by_name(self, name):
|
|
|
|
"""
|
|
|
|
:param name: The name of the style.
|
2020-04-07 09:58:21 +03:00
|
|
|
:exception OSError: If the font is not a variation font.
|
2019-06-12 13:27:11 +03:00
|
|
|
"""
|
|
|
|
names = self.get_variation_names()
|
|
|
|
if not isinstance(name, bytes):
|
|
|
|
name = name.encode()
|
|
|
|
index = names.index(name)
|
|
|
|
|
|
|
|
if index == getattr(self, "_last_variation_index", None):
|
|
|
|
# When the same name is set twice in a row,
|
|
|
|
# there is an 'unknown freetype error'
|
|
|
|
# https://savannah.nongnu.org/bugs/?56186
|
|
|
|
return
|
|
|
|
self._last_variation_index = index
|
|
|
|
|
|
|
|
self.font.setvarname(index)
|
|
|
|
|
|
|
|
def get_variation_axes(self):
|
|
|
|
"""
|
|
|
|
:returns: A list of the axes in a variation font.
|
2020-04-07 09:58:21 +03:00
|
|
|
:exception OSError: If the font is not a variation font.
|
2019-06-12 13:27:11 +03:00
|
|
|
"""
|
|
|
|
try:
|
|
|
|
axes = self.font.getvaraxes()
|
2020-06-21 13:13:35 +03:00
|
|
|
except AttributeError as e:
|
|
|
|
raise NotImplementedError("FreeType 2.9.1 or greater is required") from e
|
2019-06-12 13:27:11 +03:00
|
|
|
for axis in axes:
|
|
|
|
axis["name"] = axis["name"].replace(b"\x00", b"")
|
|
|
|
return axes
|
|
|
|
|
|
|
|
def set_variation_by_axes(self, axes):
|
|
|
|
"""
|
|
|
|
:param axes: A list of values for each axis.
|
2020-04-07 09:58:21 +03:00
|
|
|
:exception OSError: If the font is not a variation font.
|
2019-06-12 13:27:11 +03:00
|
|
|
"""
|
|
|
|
try:
|
|
|
|
self.font.setvaraxes(axes)
|
2020-06-21 13:13:35 +03:00
|
|
|
except AttributeError as e:
|
|
|
|
raise NotImplementedError("FreeType 2.9.1 or greater is required") from e
|
2019-06-12 13:27:11 +03:00
|
|
|
|
2014-07-05 02:02:46 +04:00
|
|
|
|
2019-09-30 17:56:31 +03:00
|
|
|
class TransposedFont:
|
2022-04-10 17:47:32 +03:00
|
|
|
"""Wrapper for writing rotated or mirrored text"""
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
def __init__(self, font, orientation=None):
|
2016-09-24 12:10:46 +03:00
|
|
|
"""
|
|
|
|
Wrapper that creates a transposed font from any existing font
|
|
|
|
object.
|
|
|
|
|
|
|
|
:param font: A font object.
|
|
|
|
:param orientation: An optional orientation. If given, this should
|
2022-01-15 01:02:31 +03:00
|
|
|
be one of Image.Transpose.FLIP_LEFT_RIGHT, Image.Transpose.FLIP_TOP_BOTTOM,
|
|
|
|
Image.Transpose.ROTATE_90, Image.Transpose.ROTATE_180, or
|
|
|
|
Image.Transpose.ROTATE_270.
|
2016-09-24 12:10:46 +03:00
|
|
|
"""
|
2010-07-31 06:52:47 +04:00
|
|
|
self.font = font
|
2014-07-05 02:02:46 +04:00
|
|
|
self.orientation = orientation # any 'transpose' argument, or None
|
2010-07-31 06:52:47 +04:00
|
|
|
|
2017-06-29 17:01:38 +03:00
|
|
|
def getsize(self, text, *args, **kwargs):
|
2022-06-30 15:40:40 +03:00
|
|
|
"""
|
|
|
|
.. deprecated:: 9.2.0
|
2022-07-01 12:45:36 +03:00
|
|
|
|
|
|
|
Use :py:meth:`.getbbox` or :py:meth:`.getlength` instead.
|
2022-06-30 15:40:40 +03:00
|
|
|
"""
|
2022-07-01 13:33:59 +03:00
|
|
|
deprecate("getsize", 10, "getbbox or getlength")
|
|
|
|
with warnings.catch_warnings():
|
|
|
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
2022-05-25 03:57:13 +03:00
|
|
|
w, h = self.font.getsize(text)
|
2022-01-15 01:02:31 +03:00
|
|
|
if self.orientation in (Image.Transpose.ROTATE_90, Image.Transpose.ROTATE_270):
|
2010-07-31 06:52:47 +04:00
|
|
|
return h, w
|
|
|
|
return w, h
|
|
|
|
|
2017-06-29 17:01:38 +03:00
|
|
|
def getmask(self, text, mode="", *args, **kwargs):
|
|
|
|
im = self.font.getmask(text, mode, *args, **kwargs)
|
2010-07-31 06:52:47 +04:00
|
|
|
if self.orientation is not None:
|
|
|
|
return im.transpose(self.orientation)
|
|
|
|
return im
|
|
|
|
|
2022-06-20 04:18:16 +03:00
|
|
|
def getbbox(self, text, *args, **kwargs):
|
|
|
|
# TransposedFont doesn't support getmask2, move top-left point to (0, 0)
|
|
|
|
# this has no effect on ImageFont and simulates anchor="lt" for FreeTypeFont
|
|
|
|
left, top, right, bottom = self.font.getbbox(text, *args, **kwargs)
|
|
|
|
width = right - left
|
|
|
|
height = bottom - top
|
|
|
|
if self.orientation in (Image.Transpose.ROTATE_90, Image.Transpose.ROTATE_270):
|
|
|
|
return 0, 0, height, width
|
|
|
|
return 0, 0, width, height
|
|
|
|
|
|
|
|
def getlength(self, text, *args, **kwargs):
|
|
|
|
if self.orientation in (Image.Transpose.ROTATE_90, Image.Transpose.ROTATE_270):
|
2022-06-30 15:21:39 +03:00
|
|
|
raise ValueError(
|
|
|
|
"text length is undefined for text rotated by 90 or 270 degrees"
|
|
|
|
)
|
2022-06-20 04:18:16 +03:00
|
|
|
return self.font.getlength(text, *args, **kwargs)
|
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
def load(filename):
|
2013-10-13 04:14:12 +04:00
|
|
|
"""
|
|
|
|
Load a font file. This function loads a font object from the given
|
|
|
|
bitmap font file, and returns the corresponding font object.
|
|
|
|
|
|
|
|
:param filename: Name of font file.
|
|
|
|
:return: A font object.
|
2020-04-07 09:58:21 +03:00
|
|
|
:exception OSError: If the file could not be read.
|
2013-10-13 04:14:12 +04:00
|
|
|
"""
|
2010-07-31 06:52:47 +04:00
|
|
|
f = ImageFont()
|
|
|
|
f._load_pilfont(filename)
|
|
|
|
return f
|
|
|
|
|
|
|
|
|
2019-03-21 16:28:20 +03:00
|
|
|
def truetype(font=None, size=10, index=0, encoding="", layout_engine=None):
|
2013-10-13 04:14:12 +04:00
|
|
|
"""
|
2017-11-20 18:00:23 +03:00
|
|
|
Load a TrueType or OpenType font from a file or file-like object,
|
|
|
|
and create a font object.
|
|
|
|
This function loads a font object from the given file or file-like
|
|
|
|
object, and creates a font object for a font of the given size.
|
2013-10-13 04:14:12 +04:00
|
|
|
|
2022-08-06 15:48:10 +03:00
|
|
|
Pillow uses FreeType to open font files. On Windows, be aware that FreeType
|
|
|
|
will keep the file open as long as the FreeTypeFont object exists. Windows
|
|
|
|
limits the number of files that can be open in C at once to 512, so if many
|
|
|
|
fonts are opened simultaneously and that limit is approached, an
|
2019-08-12 13:19:49 +03:00
|
|
|
``OSError`` may be thrown, reporting that FreeType "cannot open resource".
|
2022-08-06 16:01:36 +03:00
|
|
|
A workaround would be to copy the file(s) into memory, and open that instead.
|
2019-08-12 13:19:49 +03:00
|
|
|
|
2013-10-13 04:14:12 +04:00
|
|
|
This function requires the _imagingft service.
|
|
|
|
|
2017-11-20 18:00:23 +03:00
|
|
|
:param font: A filename or file-like object containing a TrueType font.
|
2019-08-12 13:04:18 +03:00
|
|
|
If the file is not found in this filename, the loader may also
|
|
|
|
search in other directories, such as the :file:`fonts/`
|
|
|
|
directory on Windows or :file:`/Library/Fonts/`,
|
|
|
|
:file:`/System/Library/Fonts/` and :file:`~/Library/Fonts/` on
|
|
|
|
macOS.
|
|
|
|
|
2022-02-22 02:32:02 +03:00
|
|
|
:param size: The requested size, in pixels.
|
2013-10-13 04:14:12 +04:00
|
|
|
:param index: Which font face to load (default is first available face).
|
2019-07-15 12:04:35 +03:00
|
|
|
:param encoding: Which font encoding to use (default is Unicode). Possible
|
2019-07-16 12:28:54 +03:00
|
|
|
encodings include (see the FreeType documentation for more
|
|
|
|
information):
|
2019-07-15 12:04:35 +03:00
|
|
|
|
|
|
|
* "unic" (Unicode)
|
|
|
|
* "symb" (Microsoft Symbol)
|
|
|
|
* "ADOB" (Adobe Standard)
|
|
|
|
* "ADBE" (Adobe Expert)
|
|
|
|
* "ADBC" (Adobe Custom)
|
|
|
|
* "armn" (Apple Roman)
|
|
|
|
* "sjis" (Shift JIS)
|
|
|
|
* "gb " (PRC)
|
|
|
|
* "big5"
|
|
|
|
* "wans" (Extended Wansung)
|
|
|
|
* "joha" (Johab)
|
|
|
|
* "lat1" (Latin-1)
|
|
|
|
|
2019-07-16 12:28:54 +03:00
|
|
|
This specifies the character set to use. It does not alter the
|
|
|
|
encoding of any text provided in subsequent operations.
|
2017-06-13 19:03:23 +03:00
|
|
|
:param layout_engine: Which layout engine to use, if available:
|
2022-01-15 01:02:31 +03:00
|
|
|
:data:`.ImageFont.Layout.BASIC` or :data:`.ImageFont.Layout.RAQM`.
|
2020-06-13 05:01:38 +03:00
|
|
|
|
|
|
|
You can check support for Raqm layout using
|
|
|
|
:py:func:`PIL.features.check_feature` with ``feature="raqm"``.
|
|
|
|
|
|
|
|
.. versionadded:: 4.2.0
|
2013-10-13 04:14:12 +04:00
|
|
|
:return: A font object.
|
2020-04-07 09:58:21 +03:00
|
|
|
:exception OSError: If the file could not be read.
|
2013-10-13 04:14:12 +04:00
|
|
|
"""
|
2019-06-11 11:42:05 +03:00
|
|
|
|
2019-04-25 09:56:18 +03:00
|
|
|
def freetype(font):
|
2017-06-13 19:03:23 +03:00
|
|
|
return FreeTypeFont(font, size, index, encoding, layout_engine)
|
2019-06-11 11:42:05 +03:00
|
|
|
|
2019-04-25 09:56:18 +03:00
|
|
|
try:
|
|
|
|
return freetype(font)
|
2019-09-30 17:56:31 +03:00
|
|
|
except OSError:
|
2022-04-10 21:20:48 +03:00
|
|
|
if not is_path(font):
|
2019-06-23 04:53:01 +03:00
|
|
|
raise
|
2015-02-27 06:48:07 +03:00
|
|
|
ttf_filename = os.path.basename(font)
|
2015-04-01 16:47:01 +03:00
|
|
|
|
2015-02-27 06:48:07 +03:00
|
|
|
dirs = []
|
2010-07-31 06:52:47 +04:00
|
|
|
if sys.platform == "win32":
|
|
|
|
# check the windows font repository
|
|
|
|
# NOTE: must use uppercase WINDIR, to work around bugs in
|
|
|
|
# 1.5.2's os.environ.get()
|
|
|
|
windir = os.environ.get("WINDIR")
|
|
|
|
if windir:
|
2015-02-27 06:48:07 +03:00
|
|
|
dirs.append(os.path.join(windir, "fonts"))
|
2019-03-21 16:28:20 +03:00
|
|
|
elif sys.platform in ("linux", "linux2"):
|
2014-12-30 04:03:39 +03:00
|
|
|
lindirs = os.environ.get("XDG_DATA_DIRS", "")
|
|
|
|
if not lindirs:
|
2015-03-21 11:32:26 +03:00
|
|
|
# According to the freedesktop spec, XDG_DATA_DIRS should
|
|
|
|
# default to /usr/share
|
2019-03-21 16:28:20 +03:00
|
|
|
lindirs = "/usr/share"
|
|
|
|
dirs += [os.path.join(lindir, "fonts") for lindir in lindirs.split(":")]
|
|
|
|
elif sys.platform == "darwin":
|
|
|
|
dirs += [
|
|
|
|
"/Library/Fonts",
|
|
|
|
"/System/Library/Fonts",
|
|
|
|
os.path.expanduser("~/Library/Fonts"),
|
|
|
|
]
|
2015-04-01 16:47:01 +03:00
|
|
|
|
2015-02-27 06:48:07 +03:00
|
|
|
ext = os.path.splitext(ttf_filename)[1]
|
2015-04-01 16:47:01 +03:00
|
|
|
first_font_with_a_different_extension = None
|
|
|
|
for directory in dirs:
|
|
|
|
for walkroot, walkdir, walkfilenames in os.walk(directory):
|
2015-02-27 06:48:07 +03:00
|
|
|
for walkfilename in walkfilenames:
|
2015-02-27 06:50:54 +03:00
|
|
|
if ext and walkfilename == ttf_filename:
|
2019-04-25 09:56:18 +03:00
|
|
|
return freetype(os.path.join(walkroot, walkfilename))
|
2019-06-11 11:42:05 +03:00
|
|
|
elif not ext and os.path.splitext(walkfilename)[0] == ttf_filename:
|
2015-02-27 06:50:54 +03:00
|
|
|
fontpath = os.path.join(walkroot, walkfilename)
|
2019-06-11 11:42:05 +03:00
|
|
|
if os.path.splitext(fontpath)[1] == ".ttf":
|
2019-04-25 09:56:18 +03:00
|
|
|
return freetype(fontpath)
|
2019-06-11 11:42:05 +03:00
|
|
|
if not ext and first_font_with_a_different_extension is None:
|
2015-04-01 16:47:01 +03:00
|
|
|
first_font_with_a_different_extension = fontpath
|
|
|
|
if first_font_with_a_different_extension:
|
2019-04-25 09:56:18 +03:00
|
|
|
return freetype(first_font_with_a_different_extension)
|
2010-07-31 06:52:47 +04:00
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
def load_path(filename):
|
2013-10-13 04:14:12 +04:00
|
|
|
"""
|
|
|
|
Load font file. Same as :py:func:`~PIL.ImageFont.load`, but searches for a
|
|
|
|
bitmap font along the Python path.
|
|
|
|
|
|
|
|
:param filename: Name of font file.
|
|
|
|
:return: A font object.
|
2020-04-07 09:58:21 +03:00
|
|
|
:exception OSError: If the file could not be read.
|
2013-10-13 04:14:12 +04:00
|
|
|
"""
|
2015-04-01 16:47:01 +03:00
|
|
|
for directory in sys.path:
|
2022-04-10 21:20:48 +03:00
|
|
|
if is_directory(directory):
|
2013-07-25 21:21:08 +04:00
|
|
|
if not isinstance(filename, str):
|
2019-09-26 15:12:28 +03:00
|
|
|
filename = filename.decode("utf-8")
|
2010-07-31 06:52:47 +04:00
|
|
|
try:
|
2015-04-01 16:47:01 +03:00
|
|
|
return load(os.path.join(directory, filename))
|
2019-09-30 17:56:31 +03:00
|
|
|
except OSError:
|
2010-07-31 06:52:47 +04:00
|
|
|
pass
|
2019-09-30 17:56:31 +03:00
|
|
|
raise OSError("cannot find font file")
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
|
|
|
|
def load_default():
|
2013-10-13 04:14:12 +04:00
|
|
|
"""Load a "better than nothing" default font.
|
|
|
|
|
|
|
|
.. versionadded:: 1.1.4
|
|
|
|
|
|
|
|
:return: A font object.
|
|
|
|
"""
|
2010-07-31 06:52:47 +04:00
|
|
|
f = ImageFont()
|
|
|
|
f._load_pilfont_data(
|
2014-07-05 02:02:46 +04:00
|
|
|
# courB08
|
2019-03-21 16:28:20 +03:00
|
|
|
BytesIO(
|
|
|
|
base64.b64decode(
|
|
|
|
b"""
|
2010-07-31 06:52:47 +04:00
|
|
|
U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AAA//oABQAAAK8AAAC0AAYABgAA////+gAGAAAAtAAAALsA
|
|
|
|
BgAGAAAAAP/6AAQAAAC7AAAAvwAGAAYAAP////oABQAAAL8AAADFAAYABgAA////+gAGAAAAxQAA
|
|
|
|
AMwABgAGAAD////6AAUAAADMAAAA0gAGAAYAAP////oABQAAANIAAADYAAYABgAA////+gAGAAAA
|
|
|
|
2AAAAN8ABgAGAAAAAP/6AAUAAADfAAAA5AAGAAYAAP////oABQAAAOQAAADqAAYABgAAAAD/+gAF
|
|
|
|
AAEA6gAAAO8ABwAGAAD////6AAYAAADvAAAA9gAGAAYAAAAA//oABQAAAPYAAAD7AAYABgAA////
|
|
|
|
+gAFAAAA+wAAAQEABgAGAAD////6AAYAAAEBAAABCAAGAAYAAP////oABgAAAQgAAAEPAAYABgAA
|
|
|
|
////+gAGAAABDwAAARYABgAGAAAAAP/6AAYAAAEWAAABHAAGAAYAAP////oABgAAARwAAAEjAAYA
|
|
|
|
BgAAAAD/+gAFAAABIwAAASgABgAGAAAAAf/5AAQAAQEoAAABKwAIAAYAAAAA//kABAABASsAAAEv
|
|
|
|
AAgABgAAAAH/+QAEAAEBLwAAATIACAAGAAAAAP/5AAX//AEyAAABNwADAAYAAAAAAAEABgACATcA
|
|
|
|
AAE9AAEABgAAAAH/+QAE//wBPQAAAUAAAwAGAAAAAP/7AAYAAAFAAAABRgAFAAYAAP////kABQAA
|
|
|
|
AUYAAAFMAAcABgAAAAD/+wAFAAABTAAAAVEABQAGAAAAAP/5AAYAAAFRAAABVwAHAAYAAAAA//sA
|
|
|
|
BQAAAVcAAAFcAAUABgAAAAD/+QAFAAABXAAAAWEABwAGAAAAAP/7AAYAAgFhAAABZwAHAAYAAP//
|
|
|
|
//kABQAAAWcAAAFtAAcABgAAAAD/+QAGAAABbQAAAXMABwAGAAAAAP/5AAQAAgFzAAABdwAJAAYA
|
|
|
|
AP////kABgAAAXcAAAF+AAcABgAAAAD/+QAGAAABfgAAAYQABwAGAAD////7AAUAAAGE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
///7AAYAAgI/AAACRgAHAAYAAAAA//kABgABAkYAAAJMAAgABgAAAAH//AAD//0CTAAAAk4AAQAG
|
|
|
|
AAAAAf//AAQAAgJOAAACUQADAAYAAAAB//kABP/9AlEAAAJUAAQABgAAAAH/+QAF//4CVAAAAlgA
|
|
|
|
BQAGAAD////7AAYAAAJYAAACXwAFAAYAAP////kABgAAAl8AAAJmAAcABgAA////+QAGAAACZgAA
|
|
|
|
Am0ABwAGAAD////5AAYAAAJtAAACdAAHAAYAAAAA//sABQACAnQAAAJ5AAcABgAA////9wAGAAAC
|
|
|
|
eQAAAoAACQAGAAD////3AAYAAAKAAAAChwAJAAYAAP////cABgAAAocAAAKOAAkABgAA////9wAG
|
|
|
|
AAACjgAAApUACQAGAAD////4AAYAAAKVAAACnAAIAAYAAP////cABgAAApwAAAKjAAkABgAA////
|
|
|
|
+gAGAAACowAAAqoABgAGAAAAAP/6AAUAAgKqAAACrwAIAAYAAP////cABQAAAq8AAAK1AAkABgAA
|
|
|
|
////9wAFAAACtQAAArsACQAGAAD////3AAUAAAK7AAACwQAJAAYAAP////gABQAAAsEAAALHAAgA
|
|
|
|
BgAAAAD/9wAEAAACxwAAAssACQAGAAAAAP/3AAQAAALLAAACzwAJAAYAAAAA//cABAAAAs8AAALT
|
|
|
|
AAkABgAAAAD/+AAEAAAC0wAAAtcACAAGAAD////6AAUAAALXAAAC3QAGAAYAAP////cABgAAAt0A
|
|
|
|
AALkAAkABgAAAAD/9wAFAAAC5AAAAukACQAGAAAAAP/3AAUAAALpAAAC7gAJAAYAAAAA//cABQAA
|
|
|
|
Au4AAALzAAkABgAAAAD/9wAFAAAC8wAAAvgACQAGAAAAAP/4AAUAAAL4AAAC/QAIAAYAAAAA//oA
|
|
|
|
Bf//Av0AAAMCAAUABgAA////+gAGAAADAgAAAwkABgAGAAD////3AAYAAAMJAAADEAAJAAYAAP//
|
|
|
|
//cABgAAAxAAAAMXAAkABgAA////9wAGAAADFwAAAx4ACQAGAAD////4AAYAAAAAAAoABwASAAYA
|
|
|
|
AP////cABgAAAAcACgAOABMABgAA////+gAFAAAADgAKABQAEAAGAAD////6AAYAAAAUAAoAGwAQ
|
|
|
|
AAYAAAAA//gABgAAABsACgAhABIABgAAAAD/+AAGAAAAIQAKACcAEgAGAAAAAP/4AAYAAAAnAAoA
|
|
|
|
LQASAAYAAAAA//gABgAAAC0ACgAzABIABgAAAAD/+QAGAAAAMwAKADkAEQAGAAAAAP/3AAYAAAA5
|
|
|
|
AAoAPwATAAYAAP////sABQAAAD8ACgBFAA8ABgAAAAD/+wAFAAIARQAKAEoAEQAGAAAAAP/4AAUA
|
|
|
|
AABKAAoATwASAAYAAAAA//gABQAAAE8ACgBUABIABgAAAAD/+AAFAAAAVAAKAFkAEgAGAAAAAP/5
|
|
|
|
AAUAAABZAAoAXgARAAYAAAAA//gABgAAAF4ACgBkABIABgAAAAD/+AAGAAAAZAAKAGoAEgAGAAAA
|
|
|
|
AP/4AAYAAABqAAoAcAASAAYAAAAA//kABgAAAHAACgB2ABEABgAAAAD/+AAFAAAAdgAKAHsAEgAG
|
|
|
|
AAD////4AAYAAAB7AAoAggASAAYAAAAA//gABQAAAIIACgCHABIABgAAAAD/+AAFAAAAhwAKAIwA
|
|
|
|
EgAGAAAAAP/4AAUAAACMAAoAkQASAAYAAAAA//gABQAAAJEACgCWABIABgAAAAD/+QAFAAAAlgAK
|
|
|
|
AJsAEQAGAAAAAP/6AAX//wCbAAoAoAAPAAYAAAAA//oABQABAKAACgClABEABgAA////+AAGAAAA
|
|
|
|
pQAKAKwAEgAGAAD////4AAYAAACsAAoAswASAAYAAP////gABgAAALMACgC6ABIABgAA////+QAG
|
|
|
|
AAAAugAKAMEAEQAGAAD////4AAYAAgDBAAoAyAAUAAYAAP////kABQACAMgACgDOABMABgAA////
|
|
|
|
+QAGAAIAzgAKANUAEw==
|
2019-03-21 16:28:20 +03:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
),
|
|
|
|
Image.open(
|
|
|
|
Bytes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