Draw bold/italic text with PIL?

Viewed 26858

How to draw bold/italic text with PIL? ImageFont.truetype(file, size) has an option to specify font size only.

6 Answers

There is no bold features as parameter till now but easily you can solve by add stroke to the text with same color of text. it will make sense as bold font next code elaborate how to use stroke

    draw.text((x, y), text, fill=color, font=font, stroke_width=2,
          stroke_fill="black")

With reference to the other answers here, my search for the name for the bold variant of Arial produced the following (arialbd.ttf):

def FindFontsVariantsWithBase(fontBase="arial"):
        import matplotlib
        system_fonts = matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf')
        # for font in np.sort(system_fonts):
        #     print(font)
        fonts = np.sort(system_fonts).tolist()
        res = [i for i in fonts if fontBase in i]
        print(res)
        
FindFontsVariantsWithBase("arial")

['C:\WINDOWS\Fonts\arial.ttf', 'C:\WINDOWS\Fonts\arialbd.ttf', 'C:\WINDOWS\Fonts\arialbi.ttf', 'C:\WINDOWS\Fonts\ariali.ttf', 'C:\Windows\Fonts\arial.ttf', 'C:\Windows\Fonts\arialbd.ttf', 'C:\Windows\Fonts\arialbi.ttf', 'C:\Windows\Fonts\ariali.ttf'] (

Related