11import base64
22import json
3+ import warnings
4+
35import numpy as np
46import zlib
5- from PIL import Image , ImageDraw , ImageFont
7+ from PIL import Image , ImageDraw
68import torch
79
810
@@ -129,14 +131,17 @@ def extract_image_data_embed(image):
129131
130132
131133def 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