import Image, ImageDraw, ImageFont, os # parse data fp = open(os.path.join(os.path.split(__file__)[0],"counts")) maxx = 0 maxy = 0 first = True sub = 0 points = [] for l in fp.readlines(): t,c = l.split() t,c = float(t),int(c) if first: sub = t first = False points.append((t-sub, c)) if c > maxy: maxy = c if (t-sub) > maxx: maxx = t - sub # process data IMAGE_X_SIZE = 250 IMAGE_Y_SIZE = 75 X_FACTOR = float(IMAGE_X_SIZE) / maxx Y_FACTOR = float(IMAGE_Y_SIZE - 10) / maxy newpoints = [(int(x[0] * X_FACTOR), IMAGE_Y_SIZE - 1 - int(x[1] * Y_FACTOR)) for x in points] newpoints.sort(lambda x,y: cmp(x[0],y[0])) # move sparkline to correct place in image newpoints = [(x[0] + 75, x[1]) for x in newpoints] im = Image.open(os.path.join(os.path.split(__file__)[0],"jono.png")) draw = ImageDraw.Draw(im) draw.line(newpoints, fill=(100,100,100)) canonical = 1157393469 canconv = int((canonical - sub) * X_FACTOR) draw.line([(canconv,10),(canconv,75)], fill=(0,255,0)) del draw im.save(os.path.join(os.path.split(__file__)[0],"jonocommunity.png"), "PNG")