Paste #179270

   
pasted on 04.05.2021 14:00
  • Edit to this paste
  • Print
  • Raw
  • Compare with paste
    #  
  • Toggle line numbers
  • Syntax highlighting  
Text paste
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
def genimage(infilename,outfilename,pos=(10,10),fill=(255,255,255,64),stroke_fill=(0,0,0,64),stroke_width=4,fontsize=100,pictext=f"я тутъ\nнаговнокодилъ"):
    infilename = f"pics/"+infilename
    if os.path.isfile(infilename):
        with Image.open(infilename).convert("RGBA") as im:
#            im = Image.open(infilename).convert("RGBA")
            size = im.size
#            imtxt = Image.new('RGBA', im.size, (255,255,255,0))
            with Image.new('RGBA', im.size, (255,255,255,0)) as imtxt:
                font = ImageFont.truetype(f"fonts/FRADMCN.TTF", fontsize)
                d = ImageDraw.Draw(imtxt)
                d.multiline_text(pos, pictext, stroke_width=stroke_width, , stroke_fill=stroke_fill, font=font, fill=fill)
                with Image.alpha_composite(im, imtxt) as combined:
                    combined.save(f"outpics/"+outfilename)
        return True
    else:
        return False
Add Comment
Author