Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Python PIL.ImageFont.truetype

Shulou Source: shulou.com Published: 2022-06-01 07:55:29 10月03日 Update

This article mainly introduces "how to use Python PIL.ImageFont.truetype". In daily operation, I believe many people have doubts about how to use Python PIL.ImageFont.truetype. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use Python PIL.ImageFont.truetype". Next, please follow the editor to study!

A brief description:

Load a font file and generate a font object. Through size, the user can specify the font size.

Code display:

From PIL import Image,ImageFont, ImageDrawimport numpy as npimage = Image.open ("bryant.jpg") font= ImageFont.truetype (font='simhei.ttf',size=np.floor (3e-2 * 3000 + 3000). Astype ('int32') # size=np.floor (3e-2 * 1000 + 0.5). Astype (' int32')) # get the font label ='{} {: .2f} '.format (' pockmarked Lin' 0.982) draw = ImageDraw.Draw (image) label = label.encode ('utf-8') draw.text ([60,50], label.decode (), fill= (255,0,0), font=font) image.show ()

Show the running results:

At this point, the study on "how to use Python PIL.ImageFont.truetype" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Fonts learning more help practical next code size objects files articles methods theories users knowledge articles results websites materials follow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Redmi Linux OPPO Reno Microsoft