[Image-SIG] How to change size of PIL fonts?

Fredrik Lundh fredrik at pythonware.com
Tue Nov 9 09:47:57 CET 2010


On Tue, Oct 12, 2010 at 1:31 PM, Dévji Chhãngã <dev.chh at gmail.com> wrote:
> Hello Image-SIG,
> I am a newbie to PIL, I have following code
>
>     def __setFont (self, filename):
>         pilfont = ImageFont.load(filename)
>         return pilfont
>
>     def drawImage (self):
>         cg = CaptchaString(4)
>         myString = cg.getString() #Some other object to get string from
>         myFont = self.__setFont('E:\\pilfonts\\timB12.pil')
>
>         img = Image.new('RGB', (220,90), '#FFFFFF')
>
>         drawText = ImageDraw.Draw(img)
>         drawText.text((6, 0), myCaptchaString, font=myFont, fill=(255, 100,
> 25))
>
>         img.save('myFile.png', 'PNG')
>
> I don't know how to set font size so that it appear larger

The "pil" fonts are simple raster fonts that have a fixed size.  To
get more flexible font scaling, you want to use TrueType fonts
instead.

</F>


More information about the Image-SIG mailing list