-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
What did you do?
I installed Pillow 3.4.2 for local development (Python 2.7.12 on Ubuntu 16.04). My deployment target is Google App Engine which unfortunately still uses PIL 1.1.7.
There appears to be a backwards incompatibility (regression?) with the vertical alignment of the zero (0) character between these libraries and versions. Pillow does not align the character correctly.
I noticed it in one particular font (Verdana 13pt) when using ImageDraw.fontmode = '1' to disable anti-aliasing. The same issue does not occur with the default fontmode value.
I have tested this across 3 different official versions of the font from various downloads on Microsoft's website and Windows. These are freely available core fonts.
What actually happened?
Please compare the alignment of the zero (0) character in the aliased lines of the following images. It is very slight but it is unfortunately a big problem in my use-case.
PIL 1.1.7
Pillow 3.4.2
Script
from PIL import Image, ImageDraw, ImageFont
import os.path
import string
path = os.path.dirname(os.path.abspath(__file__))
text = (string.digits
+ string.ascii_lowercase
+ string.ascii_uppercase
+ string.punctuation)
font_names = ['verdanab_a.ttf', 'verdanab_b.ttf', 'verdanab_c.ttf']
image = Image.new('RGB', (1250, 250))
draw = ImageDraw.Draw(image)
draw.rectangle((0, 0, image.size[0], image.size[1]), fill=(255, 255, 255))
current_y = 10
for n, font_name in enumerate(font_names):
font = ImageFont.truetype(os.path.join(path, font_name), 13)
draw_alias = ImageDraw.Draw(image)
draw_alias.fontmode = '1'
draw_alias.text(
(10, current_y),
'%s (alias): %s' % (font_name, text),
(0, 0, 0),
font=font)
current_y += 25
draw = ImageDraw.Draw(image)
draw.text(
(10, current_y),
'%s (anti-alias): %s' % (font_name, text),
(0, 0, 0),
font=font)
current_y += 50
image.save(os.path.join(path, 'output.png'), 'PNG')
