Commits

Frederic De Groef committed 9242a2d

added script to make icons from unicode string + font

Comments (0)

Files changed (2)

scripts/DejaVuSans.ttf

Binary file added.

scripts/make_icons.py

+# -*- coding: utf-8 -*-
+from PIL import Image, ImageDraw, ImageFont
+import unicodedata
+
+SIZE=(128, 128)
+BACKGROUND_COLOR = (0, 0, 0, 0)
+BACKGROUND_COLOR = 'white'
+TEXT_COLOR = 'black'
+FONT_FILE = '/Library/Fonts/GillSans.ttc'
+FONT_FILE = 'DejaVuSans.ttf'
+FONT_SIZE = 72
+
+def compute_text_position(image_size, font_size):
+    w, h = image_size
+    xc, yc = w/2, h/2
+
+    offset = font_size/2
+
+    return xc-offset, yc-offset
+
+
+if __name__=="__main__":
+
+    img = Image.new('RGBA', SIZE, BACKGROUND_COLOR)
+
+    text_font = ImageFont.truetype(FONT_FILE, FONT_SIZE)
+
+    draw = ImageDraw.Draw(img)
+
+    pos = compute_text_position(SIZE, FONT_SIZE)
+
+    text = unicodedata.lookup('ASTERISM')
+    text = u"é"
+    text = unichr(0xF000 + 0xAA)
+    text = unichr(0x3003)
+
+    draw.text(pos, text, fill=TEXT_COLOR, font=text_font)
+    img.show()
+    img.save('ico.png')