1
1
import base64
2
2
import json
3
+ import warnings
4
+
3
5
import numpy as np
4
6
import zlib
5
- from PIL import Image , ImageDraw , ImageFont
7
+ from PIL import Image , ImageDraw
6
8
import torch
7
9
8
10
@@ -129,14 +131,17 @@ def extract_image_data_embed(image):
129
131
130
132
131
133
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
+ )
132
141
from math import cos
133
142
134
143
image = srcimage .copy ()
135
144
fontsize = 32
136
- if textfont is None :
137
- from modules .images import get_font
138
- textfont = get_font (fontsize )
139
-
140
145
factor = 1.5
141
146
gradient = Image .new ('RGBA' , (1 , image .size [1 ]), color = (0 , 0 , 0 , 0 ))
142
147
for y in range (image .size [1 ]):
@@ -147,12 +152,12 @@ def caption_image_overlay(srcimage, title, footerLeft, footerMid, footerRight, t
147
152
148
153
draw = ImageDraw .Draw (image )
149
154
150
- font = ImageFont . truetype ( textfont , fontsize )
155
+ font = get_font ( fontsize )
151
156
padding = 10
152
157
153
158
_ , _ , w , h = draw .textbbox ((0 , 0 ), title , font = font )
154
159
fontsize = min (int (fontsize * (((image .size [0 ]* 0.75 )- (padding * 4 ))/ w )), 72 )
155
- font = ImageFont . truetype ( textfont , fontsize )
160
+ font = get_font ( fontsize )
156
161
_ , _ , w , h = draw .textbbox ((0 , 0 ), title , font = font )
157
162
draw .text ((padding , padding ), title , anchor = 'lt' , font = font , fill = (255 , 255 , 255 , 230 ))
158
163
@@ -163,7 +168,7 @@ def caption_image_overlay(srcimage, title, footerLeft, footerMid, footerRight, t
163
168
_ , _ , w , h = draw .textbbox ((0 , 0 ), footerRight , font = font )
164
169
fontsize_right = min (int (fontsize * (((image .size [0 ]/ 3 )- (padding ))/ w )), 72 )
165
170
166
- font = ImageFont . truetype ( textfont , min (fontsize_left , fontsize_mid , fontsize_right ))
171
+ font = get_font ( min (fontsize_left , fontsize_mid , fontsize_right ))
167
172
168
173
draw .text ((padding , image .size [1 ]- padding ), footerLeft , anchor = 'ls' , font = font , fill = (255 , 255 , 255 , 230 ))
169
174
draw .text ((image .size [0 ]/ 2 , image .size [1 ]- padding ), footerMid , anchor = 'ms' , font = font , fill = (255 , 255 , 255 , 230 ))
0 commit comments