remove embedding related image functions from images

This commit is contained in:
DepFA 2022-10-11 19:46:33 +01:00 committed by GitHub
parent c080f52cea
commit e5fbf5c755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -463,80 +463,3 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i
txt_fullfn = None
return fullfn, txt_fullfn
def addCaptionLines(lines,image,initialx,textfont):
draw = ImageDraw.Draw(image)
hstart =initialx
for fill,line in lines:
fontSize = 32
font = ImageFont.truetype(textfont, fontSize)
_,_,w, h = draw.textbbox((0,0),line,font=font)
fontSize = min( int(fontSize * ((image.size[0]-35)/w) ), 28)
font = ImageFont.truetype(textfont, fontSize)
_,_,w,h = draw.textbbox((0,0),line,font=font)
draw.text(((image.size[0]-w)/2,hstart), line, font=font, fill=fill)
hstart += h
return hstart
def captionImge(image,prelines,postlines,background=(51, 51, 51),font=None):
if font is None:
try:
font = ImageFont.truetype(opts.font or Roboto, fontsize)
font = opts.font or Roboto
except Exception:
font = Roboto
sampleImage = image
background = Image.new("RGBA", (sampleImage.size[0],sampleImage.size[1]+1024), background)
hoffset = addCaptionLines(prelines,background,5,font)+16
background.paste(sampleImage,(0,hoffset))
hoffset = hoffset+sampleImage.size[1]+8
hoffset = addCaptionLines(postlines,background,hoffset,font)
background = background.crop((0,0,sampleImage.size[0],hoffset+8))
return background
def captionImageOverlay(srcimage,title,footerLeft,footerMid,footerRight,textfont=None):
from math import cos
image = srcimage.copy()
if textfont is None:
try:
textfont = ImageFont.truetype(opts.font or Roboto, fontsize)
textfont = opts.font or Roboto
except Exception:
textfont = Roboto
factor = 1.5
gradient = Image.new('RGBA', (1,image.size[1]), color=(0,0,0,0))
for y in range(image.size[1]):
mag = 1-cos(y/image.size[1]*factor)
mag = max(mag,1-cos((image.size[1]-y)/image.size[1]*factor*1.1))
gradient.putpixel((0, y), (0,0,0,int(mag*255)))
image = Image.alpha_composite(image.convert('RGBA'), gradient.resize(image.size))
draw = ImageDraw.Draw(image)
fontSize = 32
font = ImageFont.truetype(textfont, fontSize)
padding = 10
_,_,w, h = draw.textbbox((0,0),title,font=font)
fontSize = min( int(fontSize * (((image.size[0]*0.75)-(padding*4))/w) ), 72)
font = ImageFont.truetype(textfont, fontSize)
_,_,w,h = draw.textbbox((0,0),title,font=font)
draw.text((padding,padding), title, anchor='lt', font=font, fill=(255,255,255,230))
_,_,w, h = draw.textbbox((0,0),footerLeft,font=font)
fontSizeleft = min( int(fontSize * (((image.size[0]/3)-(padding))/w) ), 72)
_,_,w, h = draw.textbbox((0,0),footerMid,font=font)
fontSizemid = min( int(fontSize * (((image.size[0]/3)-(padding))/w) ), 72)
_,_,w, h = draw.textbbox((0,0),footerRight,font=font)
fontSizeright = min( int(fontSize * (((image.size[0]/3)-(padding))/w) ), 72)
font = ImageFont.truetype(textfont, min(fontSizeleft,fontSizemid,fontSizeright))
draw.text((padding,image.size[1]-padding), footerLeft, anchor='ls', font=font, fill=(255,255,255,230))
draw.text((image.size[0]/2,image.size[1]-padding), footerMid, anchor='ms', font=font, fill=(255,255,255,230))
draw.text((image.size[0]-padding,image.size[1]-padding), footerRight, anchor='rs', font=font, fill=(255,255,255,230))
return image