Answer a question

I am trying to change the font size using python's ImageDraw library.

You can do something like this:

fontPath = "/usr/share/fonts/dejavu-lgc/DejaVuLGCSansCondensed-Bold.ttf"
sans16  =  ImageFont.truetype ( fontPath, 16 )

im  =  Image.new ( "RGB", (200,50), "#ddd" )
draw  =  ImageDraw.Draw ( im )
draw.text ( (10,10), "Run awayyyy!", font=sans16, fill="red" )

The problem is that I don't want to specify a font. I want to use the default font and just change the size of the font. This seems to me that it should be simple, but I can't find documentation on how to do this.

Answers

Per PIL's docs, ImageDraw's default font is a bitmap font, and therefore it cannot be scaled. For scaling, you need to select a true-type font. I hope it's not difficult to find a nice truetype font that "looks kinda like" the default font in your desired font-size!

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐