35 if len(sys.argv) < 5
or len(sys.argv) > 6:
36 print 'Usage: genraster.py <xsize> <ysize> <xsizecell> <ysizecell> <outline colour>'
37 print 'Note: Generated image is saved as out.png'
41 g_size = ( int(sys.argv[1]), int(sys.argv[2]) )
42 g_cell_size = ( int(sys.argv[3]), int(sys.argv[4]) )
43 if len(sys.argv) == 6:
44 g_outline = int(sys.argv[5])
48 ncells = (g_size[0] / g_cell_size[0]) * (g_size[1] / g_cell_size[1])
49 print 'Number of cells: ',ncells
50 print 'ID \tULX\tULY\tCLR\tTXTCLR\tOUTCLR'
52 img = Image.new(
"L", g_size, 255)
53 draw = ImageDraw.Draw(img)
57 for j
in range(0, g_size[1], g_cell_size[1]):
58 for i
in range(0, g_size[0], g_cell_size[0]):
60 if count < 256 / colour_step:
61 value = count * colour_step
63 value = random.randrange(0, 255)
71 font = ImageFont.truetype(
'/usr/share/fonts/truetype/freefont/FreeSans.ttf',
72 g_cell_size[1] - int(g_cell_size[1] * 0.4))
74 draw.rectangle( [(i,j), (i + g_cell_size[0], j + g_cell_size[1])], fill=value, outline=g_outline)
75 draw.text( (i,j), (
'%d' % count), fill=value_text, font=font)
77 print '%d:\t%d\t%d\t%d\t%d\t%s' % (count, i, j, value, value_text, str(g_outline))
81 img.save(g_file,
'PNG')
82 print 'Output saved: %s' % g_file