from PIL import Image, ImageFont, ImageDraw


# im = Image.new("RGB",(1060, 200))
# draw = ImageDraw.Draw(im)

# font_hindi = ImageFont.truetype("/Users/user/AppData/Local/Microsoft/Windows/Fonts/Gargi.ttf",50)
# text_hindi = "निम्नलिखित में से किस व्यक्तित्व ने ‘वंशानुक्रम के नियम’ दिए हैं?"

# draw.text((10, 90), text_hindi, font=font_hindi)
# im.show()


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

if __name__ == '__main__':

    fontname = "/Users/user/AppData/Local/Microsoft/Windows/Fonts/Gargi.ttf"
    fontsize = 20  
    text = " निम्नलिखित में से किस व्यक्तित्व ने ‘वंशानुक्रम के नियम’ दिए हैं? \n निम्नलिखित में से किस व्यक्तित्व ने ‘वंशानुक्रम के नियम’ दिए हैं?"
   
    colorText = "black"
    colorOutline = "red"
    colorBackground = "white"


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

#tede mede hindi font ko fix krne ke liye ye wali zip file me se dll files ko nikal kar,
#python.exe wali location par dalna he.. niche zip file link.
#https://drive.google.com/file/d/1BOqu6eKKKiG6dVCNEJGHA7chhR6uyF1g/view?usp=sharing

0 comments:

Post a Comment

 
Top