Skip to content

Commit d1f26d1

Browse files
committed
Merge pull request Show-Me-the-Code#41 from PanChuan/master
from PanChuan,0000 and 0001 done
2 parents 3552352 + 6ff6f06 commit d1f26d1

File tree

6 files changed

+53
-0
lines changed

6 files changed

+53
-0
lines changed

PanChuan/0000/final.png

14.9 KB
Loading
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from PIL import Image
2+
from PIL import ImageFont
3+
from PIL import ImageDraw
4+
5+
"""
6+
make an image's white part to be transparent for merging with another image
7+
"""
8+
def white_to_transparent(img):
9+
img = img.convert('RGBA')
10+
datas = img.getdata()
11+
newData=[]
12+
for item in datas:
13+
if item[0] == 255 and item[1] == 255 and item[2] == 255:
14+
newData.append((255,255,255,0))
15+
else:
16+
newData.append(item)
17+
img.putdata(newData)
18+
return img
19+
20+
if __name__ == "__main__":
21+
p1_name = "github_logo.png"
22+
p2_name = "red_reminder.png"
23+
p1_image = Image.open(p1_name)
24+
p2_image = Image.open(p2_name)
25+
p2_transparent = white_to_transparent(p2_image)
26+
p1_image.paste(p2_transparent,(0,0),p2_transparent)
27+
28+
usr_font = ImageFont.truetype("./yahei.TTF",32)
29+
draw = ImageDraw.Draw(p1_image)
30+
draw.text((152,8),u'12',font = usr_font)
31+
p1_image.save("final.png","PNG")
32+
33+

PanChuan/0000/github_logo.png

14.2 KB
Loading

PanChuan/0000/red_reminder.png

1.27 KB
Loading

PanChuan/0000/yahei.TTF

14.3 MB
Binary file not shown.

PanChuan/0001/generate_coupon.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import string
2+
import random
3+
4+
"""
5+
generate COUPON_NUM coupons,every coupon consists of
6+
COUPON_STR_LEN digit which are capital letter or 0~9
7+
"""
8+
COUPON_NUM = 200
9+
COUPON_STR_LENGTH = 8
10+
11+
if __name__ == "__main__":
12+
lst = list(string.letters)[26:] + list(string.digits)
13+
for i in range(COUPON_NUM):
14+
coupon_list = [random.choice(lst) for i in range(COUPON_STR_LENGTH)]
15+
coupon_str = "".join(coupon_list)
16+
print coupon_str
17+
18+
19+
20+

0 commit comments

Comments
 (0)