4

I'm using Pillow 3.1.1 image library and Python 3.5.1.

I'm trying to use Pillow for drawing fonts on images. But results looks absolutely ugly and unacceptable.

1st example: looks like font not antialiased. But docs contains absolutely nothing on aliasing fonts. I've tried to make some changes (e.g. set fonttype), but texts still looks terrible. 1st example

And second example. Sometimes characters just overlay each other. And I don't have any idea how it could be fixed. 2nd example

I'm so frustrated with my experience. Is it possible to fix aliasing problem in Pillow or I should look to ImageMagick side?

Aliasing problem is my main concern, I cannot use fonts rendered such way.

Thanks for your attention!

Code example:

from PIL import Image, ImageDraw, ImageFont

DEFAULT_OFFSET = (100, 160, )


def draw_text(image, text):
    base = Image.open(image).convert('RGBA')

    txt_image = Image.new('RGBA', base.size, (255, 255, 255, 0))

    ttf = get_font()
    fnt = ImageFont.truetype(ttf, 40)
    d = ImageDraw.Draw(txt_image)

    # just return some string in format 'blah-blah\nblah-blah'
    multiline = generate_multiline(txt_image, text)

    d.multiline_text(DEFAULT_OFFSET, multiline, align='left', font=fnt, fill=(40, 40, 40, 200))

    out = Image.alpha_composite(base, txt_image)

    out.show()
martineau
  • 119,623
  • 25
  • 170
  • 301
prokaktus
  • 582
  • 5
  • 12
  • PIL/pillow doesn't do anti-aliasing. Either use another package or perhaps a [workaround](http://stackoverflow.com/questions/5414639/python-imaging-library-text-rendering). – martineau Feb 14 '16 at 01:51
  • @martineau oh, it's sad. Docs should be more direct on this topic. Now I'll try to find some workaround. I've already tested ImageMagick and it's works. Thanks for your answer! – prokaktus Feb 14 '16 at 02:00
  • The workaround of first drawing the text 3x larger and then scaling it down with image anti-aliasing on resize — which pillow does support — is probably the simplest. ImageMagick (and other better packages) often have a large number of dependencies and can be a lot of work and difficult to install. They also often don't support the latest versions of Python. – martineau Feb 14 '16 at 02:29

1 Answers1

1

Accordingly to martineau comment, Pillow doesn't support font anti-aliasing.

Community
  • 1
  • 1
prokaktus
  • 582
  • 5
  • 12