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