回答編集履歴
1
Python命名規則を参考に修正
test
CHANGED
@@ -8,21 +8,23 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
FONT_FILE = "C:\Windows\Fonts\meiryob.ttc"
|
12
12
|
|
13
|
-
|
13
|
+
FONT_SIZE = 20
|
14
14
|
|
15
|
-
|
15
|
+
CANVAS_SIZE = (400, 200)
|
16
16
|
|
17
|
-
|
17
|
+
WHITE = (255, 255, 255)
|
18
18
|
|
19
|
-
|
19
|
+
BLACK = (0, 0, 0)
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
img = Image.new('RGB',
|
23
|
+
img = Image.new('RGB', CANVAS_SIZE, WHITE)
|
24
24
|
|
25
25
|
draw = ImageDraw.Draw(img)
|
26
|
+
|
27
|
+
font = ImageFont.truetype(FONT_FILE, FONT_SIZE)
|
26
28
|
|
27
29
|
|
28
30
|
|
@@ -32,15 +34,15 @@
|
|
32
34
|
|
33
35
|
# 四角形を描画
|
34
36
|
|
35
|
-
draw.rectangle([(x*50, y*40), (x*50+40, y*40+30)], fill=
|
37
|
+
draw.rectangle([(x*50, y*40), (x*50+40, y*40+30)], fill=WHITE, outline=BLACK)
|
36
38
|
|
37
39
|
# テキストを描画
|
38
40
|
|
39
|
-
font = ImageFont.truetype(fontname, fontsize)
|
40
|
-
|
41
|
-
draw.text((x*50+5, y*40), str(y * 8 + x), fill=
|
41
|
+
draw.text((x*50+5, y*40), str(y * 8 + x), fill=BLACK, font=font)
|
42
42
|
|
43
43
|
|
44
|
+
|
45
|
+
# 画像ファイルに保存
|
44
46
|
|
45
47
|
img.save("image.png")
|
46
48
|
|