Created
July 25, 2013 17:44
-
-
Save jasonsperske/6082067 to your computer and use it in GitHub Desktop.
I got tired of resizing and fixing our logo for the myriad of sizes that iPhone, Android and Facebook require, so I wrote a Python script to generate it. There are a couple of hacks (like the gap between the top and bottom half), but it generates our logo with the correct colors and ratios :)
This file contains 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
import Image, ImageDraw | |
box_height = 2 | |
box_width = 6 | |
box_gap_height = 3 | |
box_gap_width = 2 | |
background = (0,0,0) | |
level_background = (119,120,123) | |
peeks = (237,26,59) | |
level_hightlight = (245,130,32) | |
shape = [ | |
" ^ ^ ", | |
" - - ", | |
"^-^ ^-^", | |
"---^-#-", | |
"--#-##-", | |
"#######", | |
" ", | |
"-######", | |
" -#### ", | |
" --#-- ", | |
" --- ", | |
" - ", | |
" - "] | |
heart_width = (box_width*7)+(box_gap_width*6) | |
heart_height = (box_height*13)+(box_gap_height*11) | |
heart = Image.new("RGB", (heart_width, heart_height), background) | |
draw = ImageDraw.Draw(heart) | |
for y, row in enumerate(shape): | |
for x, col in enumerate(row): | |
level_x = x*(box_width+box_gap_width) | |
level_y = y*(box_height+box_gap_height) | |
if y > 6: | |
level_y -= box_gap_height | |
fill = background | |
if col is '^': | |
fill = peeks | |
elif col is '#': | |
fill = level_hightlight | |
elif col is '-': | |
fill = level_background | |
# do the PIL image/draw (in memory) drawings | |
draw.rectangle([level_x, level_y, level_x+box_width-1, level_y+box_height-1], fill=fill) | |
# PIL image can be saved as .png .jpg .gif or .bmp file (among others) | |
heart.save("fan.st-logo-"+str(heart_width)+"x"+str(heart_height)+".png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment