Advertisement
maxim_shlyahtin

PIL

Nov 25th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import io
  2. import urllib.request
  3.  
  4. from PIL import Image, ImageDraw, ImageFont
  5.  
  6.  
  7. def pic(fdc: str, txt: str):
  8.     fd = urllib.request.urlopen(fdc)
  9.     image_file = io.BytesIO(fd.read())
  10.     im = Image.open(image_file)
  11.     font = ImageFont.truetype(r'C:\Users\MAX-Ryzen\Desktop\Roboto\Roboto-Black.ttf', size=75)
  12.     draw_text = ImageDraw.Draw(im)
  13.     width, height = draw_text.textsize(txt, font=font)
  14.     position: tuple = ((im.width - width) / 2, im.height - 100)
  15.     draw_text.text(position, txt, font=font, fill='#FF0000')
  16.     return im.show()
  17.  
  18.  
  19. pic('https://squarefaction.ru/files/game/3927/gallery/20150403133829_ab1991b9.jpg',
  20.     'Как же прекрасно Таврово')
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement