Skip to content

Commit 34fff61

Browse files
committed
Finish first problem
1 parent d860beb commit 34fff61

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

NeilLi1992/0000/main.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from PIL import Image
2+
from PIL import ImageFont
3+
from PIL import ImageDraw
4+
5+
file_name = raw_input("Please input the image name, including file appendix: ")
6+
try:
7+
img = Image.open("test.jpg")
8+
s = raw_input("Please input the number to display: ")
9+
try:
10+
num = int(s)
11+
img_width = img.size[0]
12+
img_height = img.size[1]
13+
14+
font_size = 60 * img_height / 480
15+
font_height = 60
16+
font_width = 40
17+
text_x = img_width - font_width * len(str(num))
18+
text_y = 0
19+
20+
font = ImageFont.truetype("Arial.ttf", font_size)
21+
22+
draw = ImageDraw.Draw(img)
23+
draw.text((text_x, text_y), str(num), (255,0,0), font=font)
24+
25+
img.save("new_image.jpg")
26+
except:
27+
print "The input is not a number!"
28+
except:
29+
print "Can't find specified file!"

NeilLi1992/0000/new_image.jpg

22.2 KB
Loading

NeilLi1992/0000/test.jpg

45.5 KB
Loading

0 commit comments

Comments
 (0)