[Python] gdmodule true type font size

Chris Gonnerman chris.gonnerman at newcenturycomputers.net
Sun Sep 14 00:57:28 EDT 2003


----- Original Message ----- 
From: "John Hunter" <jdhunter at nitace.bsd.uchicago.edu>


> When using gdmodule to draw text using true 
> type fonts
> 
>   im.string_ttf(font, fontsize, angle, (x,y), s, color)
> 
> the docs say 'draw string s at (x,y) using the 
> TrueType font at the given pointsize and 
> angle.'  It is not clear to me how gd handles
> point size.  A fontsize of 12 should be 12/72 = 
> 1/6 inches tall but how does gd decide what an 
> inch is?  72 pixels?  Is there some scale
> parameter or constant that allows gd to make 
> the conversion from pixels to points?

No.  The underlying GD library assumes 1 point is
exactly 1 pixel.  Font metrics are pretty fuzzy,
so your mileage may vary slightly especially
with script fonts.

> I want my text to scale with image resolution 
> which is determined by a dpi parameter, and I 
> tried doing 
>
>   scale = dpi/72.0
>
>   im.string_ttf(font, scale*fontsize, angle, (x,y), s, color)
> 
> but the fonts are larger than they should be, 
> at least according to my calculations.

You've got me here.  Perhaps if I knew what you
were trying to accomplish at a bit higher level,
I might be able to make a suggestion.

Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net
http://newcenturycomputers.net







More information about the Python-list mailing list