@@ -0,0 +1,2344 @@
+import logging%0Aimport argparse%0Aimport os%0A%0Afrom PIL import Image, ImageDraw, ImageFont%0Afrom math import ceil%0A%0Adef parse_arguments():%0A%09%22%22%22%0A%09Parse command line arguments.%0A%09%22%22%22%0A%09parser = argparse.ArgumentParser()%0A%09parser.add_argument('-l','--log', dest='my_logging_level', default='DEBUG')%0A%09parser.add_argument('-s','--string', default=None, help=%22text to paint%22)%0A%09parser.add_argument('-la','--letters_across', type=int, default=6)%0A%09parser.add_argument('-f','--font_file', default='octin_spraypaint_free.ttf', help=%22name of font file in /fonts directory%22)%0A%09parser.add_argument('-id','--img_dim', type=int, default=255, help=%22dimensions of image in pixels%22)%0A%0A%09return parser.parse_args()%0A%0Adef insert_newlines(string, every):%0A%09%22%22%22%0A%09Inserts newline characters into a string at regular intervals.%0A%09%22%22%22%09%0A%09return '%5Cn'.join(string%5Bi:i+every%5D for i in xrange(0, len(string), every))%0A%0Adef woolify(text,letters_across,font_size,pixels,color=1,fontfile):%0A%09%22%22%22%0A%09Creates PIL image file of wrap-around text graphic. Defults to black stencil.%0A%09:param str text:%0A%09:param int letters_across:%0A%09:param int font_size:%0A%09:param int pixels:%0A%09:param str fontfile:%0A%09:param int%7Ctup color:%0A%09:return PIL.Image:%0A%09%22%22%22%0A%09# format and wrap string%0A%09string = text%0A%09string = string.upper()%0A%09string = string.replace(' ','')%0A%09rows_down = int(ceil(len(string)/float(letters_across)))%0A%09string_to_draw = insert_newlines(string,letters_across)%0A%0A%09# create transparent blank image%0A%09width = int(letters_across*font_size*0.575)%0A%09height = int(rows_down*font_size*.95)%0A%09img_dim = (pixels,pixels,pixels,0)%0A%09base = Image.new('RGBA', (width,height), img_dim)%0A%0A%09# import font%0A%09filepath = '/'.join(%5Bos.path.dirname(os.path.realpath(__file__)),'fonts',fontfile%5D)%0A%09fnt = ImageFont.truetype(filepath, font_size)%0A%0A%09# draw text on image%0A%09draw = ImageDraw.Draw(base)%0A%09draw.multiline_text((0,0), string_to_draw, font=fnt, fill = color)%0A%09%0A%09return base%0A%0Adef main():%0A%09args = parse_arguments()%0A%0A%09# add logging%0A%09logger = logging.getLogger(__file__)%0A%09logger.setLevel(getattr(logging, args.my_logging_level.upper()))%0A%09ch = logging.StreamHandler()%0A%09formatter = logging.Formatter('%25(asctime)s - %25(name)s - %25(levelname)s - %25(message)s')%0A%09ch.setFormatter(formatter)%0A%09logger.addHandler(ch)%0A%0A%09im = woolify(args.string,args.letters_across,args.font_size,args.img_dim)%0A%09im.show()%0A%0A%09return%0A%0Aif __name__ == %22__main__%22:%0A%09main()%0A

Create woolifier.py