Skip to content

Commit 6f754ab

Browse files
committed
Merge pull request #10780 from akx/image-emb-fonts
Mark caption_image_overlay's textfont as deprecated; fix #10778
1 parent eed7b27 commit 6f754ab

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

modules/textual_inversion/image_embedding.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import base64
22
import json
3+
import warnings
4+
35
import numpy as np
46
import zlib
5-
from PIL import Image, ImageDraw, ImageFont
7+
from PIL import Image, ImageDraw
68
import torch
79

810

@@ -129,14 +131,17 @@ def extract_image_data_embed(image):
129131

130132

131133
def caption_image_overlay(srcimage, title, footerLeft, footerMid, footerRight, textfont=None):
134+
from modules.images import get_font
135+
if textfont:
136+
warnings.warn(
137+
'passing in a textfont to caption_image_overlay is deprecated and does nothing',
138+
DeprecationWarning,
139+
stacklevel=2,
140+
)
132141
from math import cos
133142

134143
image = srcimage.copy()
135144
fontsize = 32
136-
if textfont is None:
137-
from modules.images import get_font
138-
textfont = get_font(fontsize)
139-
140145
factor = 1.5
141146
gradient = Image.new('RGBA', (1, image.size[1]), color=(0, 0, 0, 0))
142147
for y in range(image.size[1]):
@@ -147,12 +152,12 @@ def caption_image_overlay(srcimage, title, footerLeft, footerMid, footerRight, t
147152

148153
draw = ImageDraw.Draw(image)
149154

150-
font = ImageFont.truetype(textfont, fontsize)
155+
font = get_font(fontsize)
151156
padding = 10
152157

153158
_, _, w, h = draw.textbbox((0, 0), title, font=font)
154159
fontsize = min(int(fontsize * (((image.size[0]*0.75)-(padding*4))/w)), 72)
155-
font = ImageFont.truetype(textfont, fontsize)
160+
font = get_font(fontsize)
156161
_, _, w, h = draw.textbbox((0, 0), title, font=font)
157162
draw.text((padding, padding), title, anchor='lt', font=font, fill=(255, 255, 255, 230))
158163

@@ -163,7 +168,7 @@ def caption_image_overlay(srcimage, title, footerLeft, footerMid, footerRight, t
163168
_, _, w, h = draw.textbbox((0, 0), footerRight, font=font)
164169
fontsize_right = min(int(fontsize * (((image.size[0]/3)-(padding))/w)), 72)
165170

166-
font = ImageFont.truetype(textfont, min(fontsize_left, fontsize_mid, fontsize_right))
171+
font = get_font(min(fontsize_left, fontsize_mid, fontsize_right))
167172

168173
draw.text((padding, image.size[1]-padding), footerLeft, anchor='ls', font=font, fill=(255, 255, 255, 230))
169174
draw.text((image.size[0]/2, image.size[1]-padding), footerMid, anchor='ms', font=font, fill=(255, 255, 255, 230))

0 commit comments

Comments
 (0)