Pillow: draw.text() function generate pure black word?

Created on 18 Jan 2019  路  2Comments  路  Source: python-pillow/Pillow

What did you do?

I want to add pure black text on a image with white background.

What did you expect to happen?

The whole image just has two kinds of color: black and white.

What actually happened?

At the edge of the words on generated image, many other colors appears.

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: 3.5
  • Pillow: 5.3.0
directory_name = "dataset/guwen_noise"
target_name = "dataset/watermark"
image = Image.new(mode='L', size=(64, 64), color='white')
draw_table = ImageDraw.Draw(im=image)
draw_table.text(xy=(0, 0), text='xxsad', fill='#000000', font=ImageFont.truetype(os.path.join("fonts", "Microsoft-YaHei-Regular.ttc"), 20))

image.save('my_test.png', 'PNG')

tim 20190118174110

As we can see, many pixels are filled with other color. And I find it's useless to modify the "mode" parameter. I would appreciate it very much if you could help me!

Most helpful comment

Let's get this clear: you want to disable antialiasing?

All 2 comments

Let's get this clear: you want to disable antialiasing?

Try to set draw_table.fontmode = "1"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maxhumber picture maxhumber  路  3Comments

mmalenta picture mmalenta  路  3Comments

thinrhino picture thinrhino  路  3Comments

nomarek picture nomarek  路  3Comments

indirectlylit picture indirectlylit  路  4Comments