win32 PIL fonts?

Pete Shinners pete at shinners.org
Sat Jan 5 00:00:53 EST 2002


Bengt Richter wrote:

> Is there a module that lets one load .ttf or .pfb fonts for use in PIL?
> I saw that pyFT is a Freetype wrapper, and it looks like enough pieces
> are around to do stuff one way or another, but is there something easy
> to make something like

it might be a bit overkill, and can only save BMP, but my pygame library 
can do the trick. http://www.pygame.org

     import pygame, pygame.image, pygame.font
     pygame.init()

     color = 255, 255, 255
     background = 0, 0, 128
     font = pygame.font.Font('myfontfile.ttf', 30)
     image = font.render('hello pygame', 1, color, background)
     pygame.image.save(image, "myfonttext.bmp")

the second "1" argument to Font.render does antialiasing.
i suppose you could display the image pretty easily too..

     window = pygame.display.set_mode(image.get_size())
     window.blit(image, (0,0))
     pygame.display.flip()


i'm sure it's not hard with the freetype or pil libraries either, but 
i'm afraid i've not used them for font rendering before.




More information about the Python-list mailing list