Created
July 16, 2013 22:44
-
-
Save edhiley/6015883 to your computer and use it in GitHub Desktop.
Creates gmail-app like icons, very limited ... get the font from google fonts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageDraw, ImageFont | |
import string | |
import math | |
# colours from www.flatuicolors.com | |
COLOURS = dict(turquoise="#1abc9c", | |
emerald="#2ecc71", | |
peterRiver="#3498db", | |
amethyst="#9b59b6", | |
wetAsphalt="#34495e", | |
greenSea="#16a085", | |
nephritis="#27ae60", | |
belizeHole="#2980b9", | |
wisteria="#8e44ad", | |
midnightBlue="#2c3e50", | |
sunFlower="#f1c40f", | |
carrot="#e67e22", | |
alizarin="#e74c3c", | |
clouds="#ecf0f1", | |
concrete="#95a5a6", | |
orange="#f39c12", | |
pumpkin="#d35400", | |
pomegranite="#c0392b", | |
silver="#bdc3c7", | |
asbestos="#7f8c8d") | |
W, H = (256, 256) | |
text = "A" | |
color_index = int(math.floor(string.uppercase.index(text) / 1.3)) | |
colour = COLOURS.items()[color_index][1] | |
image = Image.new("RGBA", (W,H), colour) | |
font = ImageFont.truetype("Roboto-Light.ttf", int(H / 1.05)) | |
draw = ImageDraw.Draw(image) | |
w, h = draw.textsize(text, font) | |
draw = draw.text(((W-w)/2,(H-h)/2), text,("white"), font=font) | |
image.save("test.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment