Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image, ImageDraw, ImageFont
- # FullHD Size (1920 x 1080)
- def GenerateImage_CenteredText(TextString, FileName, FontPath, TextSize):
- try:
- IMG_MODE = "RGB"
- SIZE_X, SIZE_Y = 1920, 1080
- IMG_SIZE = (SIZE_X, SIZE_Y)
- IMG_COLOR = "#BE8DF5"
- IMG_NAME = str(FileName) + str(".png")
- IMG_FONT = ImageFont.truetype(FontPath, TextSize)
- IMG_TEXT = TextString
- IMG = Image.new(IMG_MODE, IMG_SIZE, IMG_COLOR)
- Draw = ImageDraw.Draw(IMG)
- Size_X, Size_Y = Draw.textsize(IMG_TEXT, font=IMG_FONT)
- CENTERED_POSITION = ((SIZE_X - Size_X) / 2, (SIZE_Y - Size_Y) / 2)
- Draw.text(CENTERED_POSITION, IMG_TEXT, font=IMG_FONT, fill=(255, 255, 255))
- IMG.save(IMG_NAME)
- return IMG
- except Exception as Ex:
- return Ex
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement