From 42a5a743c18d87d9c54ed5ff11303caf9fcd0b4b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 6 Aug 2022 22:48:10 +1000 Subject: [PATCH 1/2] Note to Windows users that FreeType will keep the font file open --- src/PIL/ImageFont.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index a3b711c6077..efd702b8685 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -906,9 +906,10 @@ def truetype(font=None, size=10, index=0, encoding="", layout_engine=None): 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. - Pillow uses FreeType to open font files. If you are opening many fonts - simultaneously on Windows, be aware that Windows limits the number of files - that can be open in C at once to 512. If you approach that limit, an + 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 ``OSError`` may be thrown, reporting that FreeType "cannot open resource". This function requires the _imagingft service. From c24b6ef4f095ba2b9e3f35d8f470d931b1310a11 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 6 Aug 2022 23:01:36 +1000 Subject: [PATCH 2/2] Document workaround --- src/PIL/ImageFont.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index efd702b8685..9386d008602 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -911,6 +911,7 @@ def truetype(font=None, size=10, index=0, encoding="", layout_engine=None): 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 ``OSError`` may be thrown, reporting that FreeType "cannot open resource". + A workaround would be to copy the file(s) into memory, and open that instead. This function requires the _imagingft service.