Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions modules/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import piexif
import piexif.helper
from PIL import Image, ImageFont, ImageDraw, ImageColor, PngImagePlugin, ImageOps
from PIL import __version__ as pillow_version
from pkg_resources import parse_version
# pillow_avif needs to be imported somewhere in code for it to work
import pillow_avif # noqa: F401
import string
Expand Down Expand Up @@ -168,9 +170,18 @@ def draw_texts(drawing, draw_x, draw_y, lines, initial_fnt, initial_fontsize):
for line in lines:
fnt = initial_fnt
fontsize = initial_fontsize
while drawing.multiline_textsize(line.text, font=fnt)[0] > line.allowed_width and fontsize > 0:
fontsize -= 1
fnt = get_font(fontsize)
if parse_version(pillow_version) >= parse_version('10.0.0'):
# New code for Pillow 10.0.0+
text_width, text_height = drawing.multiline_textbbox((0, 0), line.text, font=fnt)[2:]
while text_width > line.allowed_width and fontsize > 0:
fontsize -= 1
fnt = get_font(fontsize)
text_width, text_height = drawing.multiline_textbbox((0, 0), line.text, font=fnt)[2:]
else:
# Old code for Pillow versions below 10.0.0
while drawing.multiline_textsize(line.text, font=fnt)[0] > line.allowed_width and fontsize > 0:
fontsize -= 1
fnt = get_font(fontsize)
drawing.multiline_text((draw_x, draw_y + line.size[1] / 2), line.text, font=fnt, fill=color_active if line.is_active else color_inactive, anchor="mm", align="center")

if not line.is_active:
Expand Down
6 changes: 3 additions & 3 deletions requirements_versions.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
setuptools==69.5.1 # temp fix for compatibility with some old packages
GitPython==3.1.32
Pillow==9.5.0
Pillow==10.4.0
accelerate==0.31.0
blendmodes==2022
blendmodes==2024.1.1
clean-fid==0.1.35
diskcache==5.6.3
einops==0.4.1
Expand All @@ -14,7 +14,7 @@ inflection==0.5.1
jsonmerge==1.8.0
kornia==0.6.7
lark==1.1.2
numpy==1.26.2
numpy==1.26.4
omegaconf==2.2.3
open-clip-torch==2.20.0
piexif==1.1.3
Expand Down