working on test

This commit is contained in:
Micah Chambers 2016-06-12 19:12:43 -07:00
parent e3ad94e17e
commit 2801b425fc
2 changed files with 31 additions and 1 deletions

View File

@ -344,7 +344,7 @@ class ImageDraw(object):
line_bounding_boxes)
def draw_at_pos(self, text, font=None, line_height=None,
def text_at_pos(self, text, font=None, line_height=None,
line_height_percent=None, origin=(0, 0), align_x='exact',
align_y='exact', justify_x='left', fill=None):
"""

View File

@ -180,6 +180,36 @@ try:
self.assert_image_similar(im, target_img, .5)
def test_render_text_at_pos(self):
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
# Test that text() correctly connects to multiline_text()
# and that align defaults to left
im = Image.new(mode='RGB', size=(300, 100))
draw = ImageDraw.Draw(im)
draw.text_at_pos((0, 0), TEST_TEXT, font=ttf)
target = 'Tests/images/multiline_text.png'
target_img = Image.open(target)
self.assert_image_similar(im, target_img, .5)
# Test align center and right
for align_x in ('left', 'center', 'right', 'exact'):
for align_y in ('top', 'middle', 'bottom', 'exact'):
for justify_x in ('left', 'right', 'center'):
im = Image.new(mode='RGB', size=(300, 100))
ext = '%s_%s_%s' % (align_x, align_y, justify_x)
draw = ImageDraw.Draw(im)
draw.text_at_pos(TEST_TEXT, font=ttf, align_x=align_x,
align_y=align_x, justify_x=justify_x)
del draw
target = 'Tests/images/text_at_pos_'+ext+'.png'
target_img = Image.open(target)
self.assert_image_similar(im, target_img, .5)
def test_unknown_align(self):
im = Image.new(mode='RGB', size=(300, 100))
draw = ImageDraw.Draw(im)