Repository navigation
Expand file tree
/
Copy pathfont-add-border.py
More file actions
executable file
·70 lines (53 loc) · 2.33 KB
/
Copy pathfont-add-border.py
File metadata and controls
executable file
·70 lines (53 loc) · 2.33 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
# SuperTux
# Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from PIL import Image
import argparse
import tempfile
# Add a 1 pixel border around every glyph in a font
def fix_font_file(filename, glyph_width, glyph_height):
print("Processing %s %dx%d" % (filename, glyph_width, glyph_height))
img = Image.open(filename)
w, h = img.size
print("Image size: %dx%d" % (w, h))
assert w % glyph_width == 0, "image not multiple of glyph width"
assert h % glyph_height == 0, "image not multiple of glyph height"
w_g = w // glyph_width
h_g = h // glyph_height
print("Glyphs: %ax%a" % (w_g, h_g))
out = Image.new("RGBA", (w_g * (glyph_width + 2), h_g * (glyph_height + 2)), color=5)
for y in range(0, h_g):
for x in range(0, w_g):
ix = x * glyph_width
iy = y * glyph_height
ox = x * (glyph_width + 2) + 1
oy = y * (glyph_height + 2) + 1
glyph = img.crop((ix, iy, ix + glyph_width, iy + glyph_height))
out.paste(glyph, (ox, oy))
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as f:
out.save(f)
print("File saved as %s" % f.name)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='rFactor MAS packer')
parser.add_argument('FILE', action='store', type=str,
help='font image to change')
parser.add_argument('GLYPH_WIDTH', action='store', type=int,
help='glyph width')
parser.add_argument('GLYPH_HEIGHT', action='store', type=int,
help='glyph height')
args = parser.parse_args()
fix_font_file(args.FILE, args.GLYPH_WIDTH, args.GLYPH_HEIGHT)
# EOF #