Discussion:
fonts in PIL ?
Stéphane Ninin
2004-02-08 21:22:35 UTC
Permalink
Hello all,

I am writing (on Linux Redhat 9)
some script to make graphs using PIL, from a set of points.

All is ok, except that there seems to be no font coming with PIL.
Where could I fond some ?
Also, are there some real examples of use of fonts in PIL ?
load
ImageFont.load(file) => Font instance
Loads a font from the given file, and returns the corresponding font
object. If this function fails, it raises an IOError exception.
but should "file" be the full path to the font,
or just a font name ?
truetype
ImageFont.truetype(file, size) => Font instance
Load a TrueType or OpenType font file, and create a font object. This
function loads a font object from the given file, and creates a font
object for a font of the given size.
On Windows, if the given file name does not exist, the loader also looks
in Windows fonts directory.
Also, only true type fonts can be resized:
there is no easy way to resize standard fonts ?
(I am not a font expert :) )


Thanks in advance for your answers.


Regards,
--
Stephane Ninin
Cousin Stanley
2004-02-09 16:10:17 UTC
Permalink
| ....
| Also, are there some real examples of use of fonts in PIL ?
| ....

St?phanie ....

Following is an example of using the PIL ImageFont class ....

'''
Module ....... pil_ImageFont.py
Code_By ...... Stanley C. Kitching
Code_Date .... 2004-02-09
'''

import Image
import ImageFont
import ImageDraw

this_list = [ " Look, up in the sky ......... " ,
" It's a bird ................ " ,
" It's a plane ............... " ,
" It's S u p e r M a n !!!!! " ,
" " ,
" More powerful" ,
" than a locomotive !!!!!!" ,
" " ,
" Able to leap tall buildings" ,
" in a single bound !!!!!!" ]

this_image = Image.new( 'RGB' , ( 360 , 240 ) )

# Adjust dir_PIL path to YOUR installation

dir_PIL = 'K:/Python23/Lib/site-packages/PIL/'

dir_fonts = dir_PIL + 'pilfonts/'

this_font = 'courB12.pil'

i_font = ImageFont.load( dir_fonts + this_font )

this_col = 10
this_row = 10
row_inc = 20

for this_line in this_list :

i_draw = ImageDraw.Draw( this_image )

i_draw.text( ( this_col , this_row ) , this_line , font = i_font )

this_row += row_inc

this_image.save( 'pil_ImageFont.png' )

this_image.show()
--
Cousin Stanley
Human Being
Phoenix, Arizona
Cousin Stanley
2004-02-10 23:37:36 UTC
Permalink
| Well, it works just fine, thanks again.

You're welcome ....

| Where did you find all these options ?

The PIL documentation I have is in a PDF file
that I think came from the following link ....

http://www.pythonware.com/products/pil/pil-handbook.pdf

I don't know if the PDF version is still there
and if it is, wheter or not if is in sync ( older or newer than )
with HTML version from the link you gave

http://www.pythonware.com/library/pil/handbook/index.htm

Those two sources are the only ones I have ....
--
Cousin Stanley
Human Being
Phoenix, Arizona
Cousin Stanley
2004-02-09 16:54:27 UTC
Permalink
| St?phane please, St?phanie is a woman's name here

St?phane ....

Sorry for the typo ....

Over-clocked fingers NOT synchronized with feeble brain ....

| Thanx for the script, ....

You're welcome ....
--
Cousin Stanley
Human Being
Phoenix, Arizona
Cousin Stanley
2004-02-09 23:45:38 UTC
Permalink
| ....
| am I dreaming or all fonts are in white ?
| (and so cannot be seen if you have a white background) ?
|
| Or is there a way to set the color of text ?

St?phane ....

# Set the background color when creating the image ....

this_image = Image.new( 'RGB' , ( 360 , 240 ) , 'white' )

# Set the fill color when drawing the text ....

i_draw.text( ( this_col , this_row ) ,
this_line ,
font = i_font ,
fill = 'black' )
--
Cousin Stanley
Human Being
Phoenix, Arizona
Stéphane Ninin
2004-02-09 17:47:16 UTC
Permalink
[ ..]
I had a quick look at it and at the pilfonts...

Just one last question:
am I dreaming or all fonts are in white ?
(and so cannot be seen if you have a white background) ?

Or is there a way to set the color of text ?

Regards,
--
St?phane Ninin
Jarek Zgoda
2004-02-08 21:43:09 UTC
Permalink
Post by Stéphane Ninin
All is ok, except that there seems to be no font coming with PIL.
Where could I fond some ?
http://effbot.org -- look for pilfonts in download section.
--
Jarek Zgoda
http://jpa.berlios.de/
Loading...