[Image-SIG] Font Support in PIL

Jesse Montrose jesse@spine.com
Sat, 4 Aug 2001 22:33:05 -0700


thanks for putting up those fonts, Kevin!  

i'm having a "missing space" problem that i'm assuming someone else
has run into with font rendering.  i've posted the problem output at

   http://www.spine.com/fontproblem.gif 

and the script used to generate it is below.  it renders the string
"one two three" in five different fonts, and three sizes per font.

as you can see from the picture, many of the output lines are
completely missing their spaces.

any tips?




#!/usr/bin/python

import Image, ImageDraw, ImageFont
import types

script = [
	(255,0,0),
	"font/Garamond_14_72.pil",
	"font/Verdana_12_72.pil",
	"font/Arial_14_72.pil",
	"font/Bookman Old Style_14_72.pil",
	"font/Courier New_14_72.pil",
	 (0,255,0), 
	"font/Garamond_24_72.pil",
	"font/Verdana_22_72.pil",
	"font/Arial_24_72.pil",
	"font/Bookman Old Style_24_72.pil",
	"font/Courier New_24_72.pil",
	(0,0,255),
	"font/Garamond_48_72.pil",
	"font/Verdana_48_72.pil",
	"font/Arial_48_72.pil",
	"font/Bookman Old Style_48_72.pil",
	"font/Courier New_48_72.pil"]

colors = [(255,0,0), (0,255,0), (0,0,255)]

im = Image.new('RGB', (400, 600))
draw = ImageDraw.Draw(im)

testString = "one two three"
colorIndex = -1

top = 0
fontName = 0
color = 0
for elem in script:
	if type(elem) == types.TupleType:
		color = elem
		continue
	else:
		fontName = elem
	font = ImageFont.load (fontName)
	draw.setfont(font)
	draw.text ((10,top),
			   testString, fill=color)
	top = top + font.getsize(testString)[1]

del draw

im.save("fontproblem.gif")


On Thu, Jun 22, 2000 at 08:01:16AM -0700, kcazabon wrote:
> Hi Loris;
> 
> I while back I created a whole bunch of font sets for PIL because I was
> having the same problems.  One of the other users (Piers Lauder) kindly
> provided FTP space for them, as they're quite large (even when zipped).
> 
> They're available at the following address if you'd like to download
> "pre-PIL-ified" fonts.
> 
> http://www.cs.usyd.edu.au/~piers/python/pilfonts.html
> 
> Kevin Cazabon
> 
> 
> From: "Loris Caren" <loris@caren.demon.co.uk>
> To: <image-sig@python.org>
> Sent: Wednesday, June 21, 2000 4:20 AM
> Subject: [Image-SIG] Font Support in PIL
> 
> 
> > Hello,
> > I'm try to create some fonts that can be read by the ImageFont library
> using
> > bdf2pil.  However it dies in font2image saying that Image.core.hex_decoder
> > should have two args rather than the one provided.
> > I've tried greping for hex_decoder in the library but dont get any hits.
> Can
> > anybody else get this to work?  Without it I can't see how that I can
> write
> > text using the ImageDraw library.
> >
> > _______________________________________________
> > Image-SIG maillist  -  Image-SIG@python.org
> > http://www.python.org/mailman/listinfo/image-sig
> 
> 

-- 
  pgp  14 4b eb f7 62 13 2e c1                    jesse montrose
print  31 95 e6 82 25 64 7b 43                    www.spine.com