forked from rbanffy/3270font
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_sample_image.py
executable file
·34 lines (27 loc) · 1.21 KB
/
generate_sample_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
"""
Generate a sample rendering of the base font.
"""
from PIL import Image, ImageDraw, ImageFont
SAMPLE_TEXT = u'''ABCDEFHI1234567890Oijl1IS5qt"'$#!@{}[]()<>çéáÁÑÃÏ¡²³¤€¼½¾'''\
u'''‘’¥×÷ßø«»®␀␍␊␌▶⚓⯒✘✔✼✎␢…⌘⏎⌫⏻⏼➜●ЯЖ'''
HEIGHT = 200
WIDTH = 800
background = Image.new("RGBA", (WIDTH, HEIGHT), (255, 255, 255))
foreground = Image.new("RGBA", (WIDTH, HEIGHT), (255, 255, 255, 0))
draw_b = ImageDraw.Draw(background)
draw_f = ImageDraw.Draw(foreground)
size_font = ImageFont.truetype('./build/3270Medium.otf', size=15)
y = 0
for size in range(15, 55, 5):
sample_font = ImageFont.truetype('./build/3270Medium.otf', size=size)
offset = size * .7
y += offset
# Draw the background reference lines.
draw_b.line(((0, y+size*.2), (WIDTH, y+size*.2)), (100, 100, 255, 255), 1)
draw_b.line(((0, y+offset), (WIDTH, y+offset)), (100, 100, 255, 255), 1)
# Draw the sample text.
draw_f.text((0, y), str(size), (0, 0, 0, 255), font=size_font)
draw_f.text((20, y), SAMPLE_TEXT, (0, 0, 0, 255), font=sample_font)
img = Image.alpha_composite(background, foreground)
img.save("build/3270Medium_sample.png")