Skip to content

Commit 9d1bbf3

Browse files
committed
Finished problem 0
1 parent d860beb commit 9d1bbf3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

marzinz/0000/add_num.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from PIL import Image, ImageDraw, ImageFont
2+
3+
def add_num_to_img(image_path, sign="42"):
4+
im = Image.open(image_path)
5+
width, height = im.size
6+
7+
draw = ImageDraw.Draw(im)
8+
font = ImageFont.truetype("arial.ttf", min(width//6, height//6))
9+
draw.text((width*0.75, height*0.075), sign, font=font, fill=(255,33,33, 255))
10+
11+
left, right = image_path.rsplit(".", 1)
12+
new_image_path = left + "_" + sign + "." + right
13+
im.save(new_image_path)
14+
15+
if __name__ == '__main__':
16+
# for test
17+
add_num_to_img("./sample.jpg")
18+
print "Finished."

marzinz/0000/sample.jpg

31.5 KB
Loading

0 commit comments

Comments
 (0)