[Image-SIG] text render quality (jpg attached)

Christopher Barker Chris.Barker at noaa.gov
Wed Nov 28 21:09:10 CET 2007


Scott Frankel wrote:
> Point well taken regarding jpeg.  Nonetheless, my text is still looking 
> pretty funky.  Any other suggestions

I've repeated your experiment, and yes, it doesn't look so good. I think 
the issue is that that is a very skinny font, and rendering it with 
anti-aliasing at 72dpi (which it appears is the default -- I can't find 
anything in the PIL docs about setting dpi, or what unit the "size" of a 
font is given in). Some systems use tricks to line up the lines of a 
font with the pixels to make this sort of thing look better (MS 
ClearType). Here's a bit of discussion about that:

http://www.antigrain.com/research/font_rasterization/index.html

It looks like PIL isn't trying to do anything special in that regard. 
You might try the agg renderer -- I don't know if it's different, but it 
might be.


I'd use a thicker font, it looks much better -- see enclosure.

#!/usr/bin/env python

import Image
from PIL import Image
import ImageFont
img = Image.new("RGB", (512, 256), (128, 128, 128))
import ImageDraw
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("/Library/Fonts/HelveticaNeue.dfont", 24, 
encoding="armn")
draw.text((10, 10), "hello world", font=font)
font = ImageFont.truetype("/Library/Fonts/HelveticaCY.dfont", 24, 
encoding="armn")
draw.text((10, 40), "hello world", font=font)
print "size of X is:", font.getsize("X")
img.save("foo.png", "PNG")




-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.png
Type: image/png
Size: 7489 bytes
Desc: not available
Url : http://mail.python.org/pipermail/image-sig/attachments/20071128/a14f006c/attachment.png 


More information about the Image-SIG mailing list