[Image-SIG] Bad antialias? (in Python Imaging Library 1.1.5)
kevin@cazabon.com
kevin at cazabon.com
Mon Sep 19 20:45:03 CEST 2005
I've managed to do fairly decent anti-aliased text from bitmap PIL fonts,
even including colored text, as follows:
1) render the text at 2x the desired size (or 3x or 4x depending on how
fine you want the anti-aliasing to be...). Render it in black on a plain
white background of the correct size for the text only.
2) resize the text to the right size (using im.resize()), using bicubic
interpolation (i.e. use the method = Image.BICUBIC arg to resize)
3) create a colored image the same size as the text - in the color you want
the text to be in the final output.
4) paste the lot into the final image, using the text image as a mask.
(i.e. final = original.paste(colorImage, (x, y), textMask)
Resizing using BICUBIC will give the text anti-aliased edges as desired.
Kevin.
----- Original Message -----
From: "Laszlo Zsolt Nagy" <gandalf at designaproduct.biz>
To: <image-sig at python.org>
Sent: Monday, September 19, 2005 10:42 AM
Subject: [Image-SIG] Bad antialias? (in Python Imaging Library 1.1.5)
> I create a fully transparent red image this way:
>
> size = (400,400)
> img = Image.new('RGBA',size,(255,0,0,0))
>
> Then I draw an (antialiased) text on it:
>
> drawer = ImageDraw.Draw(img)
> font = ImageFont.truetype('arc.ttf',12)
> drawer.text((0,0),"This text is 12pt",font=font,fill=(0,0,0,255))
>
> This is what I get (image drawn on a gray background):
>
> http://mess.hu/download/bad_antialias.png
>
> Apparently, antialiasing will use a mixture of the background color and
> the text color on the edges.
> I think this is good only if the background is fully opaque. Is there a
> workaround?
>
> Is this a PIL bug or a feature?
>
> Thanks,
>
> Les
>
>
> _______________________________________________
> Image-SIG maillist - Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>
>
>
More information about the Image-SIG
mailing list