Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

text to png python

import Image
import ImageDraw
import ImageFont

def getSize(txt, font):
    testImg = Image.new('RGB', (1, 1))
    testDraw = ImageDraw.Draw(testImg)
    return testDraw.textsize(txt, font)

if __name__ == '__main__':

    fontname = "Arial.ttf"
    fontsize = 11   
    text = "example@gmail.com"
    
    colorText = "black"
    colorOutline = "red"
    colorBackground = "white"


    font = ImageFont.truetype(fontname, fontsize)
    width, height = getSize(text, font)
    img = Image.new('RGB', (width+4, height+4), colorBackground)
    d = ImageDraw.Draw(img)
    d.text((2, height/2), text, fill=colorText, font=font)
    d.rectangle((0, 0, width+3, height+3), outline=colorOutline)
    
    img.save("D:/image.png")
Comment

PREVIOUS NEXT
Code Example
Python :: is microsoft teams free 
Python :: first non repeating charcter in string ython 
Python :: python main template 
Python :: how to separate date and time in python 
Python :: google oauth python tutorial 
Python :: python left string 
Python :: how to find the summation of all the values in a tuple python 
Python :: detect grayscale image in python opencv 
Python :: # get the largest number in a list and print its indexes 
Python :: Math Module radians() Function in python 
Python :: python global keyword 
Python :: [1,2,3,4,5] 
Python :: ValueError: tuple.index(x): x not in tuple 
Python :: discord api python putting ids in a list 
Python :: img_sm = pygame.transform.scale(img, (32, 32)) 
Python :: findout age in python 
Python :: Randome Word generator from consonant, vowel and specific string 
Python :: python random password generator 
Python :: build an ai writer web crapper 
Python :: bolumden kalan python 
Shell :: add-apt-repository command not found 
Shell :: woeusb ubuntu install 
Shell :: mac restart audio driver 
Shell :: ubuntu restart mariadb 
Shell :: date linux format yyyymmdd 
Shell :: install metasploitable on ubuntu 
Shell :: how to check windows powershell version 
Shell :: npm ERR! Maximum call stack size exceeded ubuntu 
Shell :: linux ls command file size human readable 
Shell :: Installing graphviz in Linux 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =