From d25101d04eb55dd3640cc5e69e63f869bbcd40bb Mon Sep 17 00:00:00 2001 From: PhilGao Date: Thu, 14 Dec 2017 17:12:28 +0800 Subject: [PATCH 1/3] Create 0000.py Install Pillow module Reference : http://pillow.readthedocs.io/en/latest/reference/ImageDraw.html?highlight=draw#PIL.ImageDraw.PIL.ImageDraw.ImageDraw.getfont --- phil.gao/0000.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 phil.gao/0000.py diff --git a/phil.gao/0000.py b/phil.gao/0000.py new file mode 100644 index 00000000..c5535c53 --- /dev/null +++ b/phil.gao/0000.py @@ -0,0 +1,23 @@ +from PIL import Image, ImageDraw, ImageFont +# get an image +base = Image.open(r"C:\Users\hagao\Desktop\Koala.jpg").convert('RGBA') + +#get image size +size = base.size +# define the font size using points +Fsize = 80 + +#font position +fpos = (size[0]-Fsize,0) + +# get a font +fnt = ImageFont.truetype(r'C:\windows\Fonts\Arial.ttf', Fsize) +# get a drawing context +d = ImageDraw.Draw(base) + +# draw text, left up point ,font , color using RGBA +d.text(fpos, "4", font=fnt, fill=(255,0,0,1)) + + +base.save(r'C:\Users\hagao\Desktop\KoalaNum.bmp') +base.show() From c194434183c135eb2e56efc4e18891b2b434d9db Mon Sep 17 00:00:00 2001 From: PhilGao Date: Fri, 15 Dec 2017 18:11:28 +0800 Subject: [PATCH 2/3] commit the solution for 0001 --- phil.gao/0001.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 phil.gao/0001.py diff --git a/phil.gao/0001.py b/phil.gao/0001.py new file mode 100644 index 00000000..f6a28d86 --- /dev/null +++ b/phil.gao/0001.py @@ -0,0 +1,15 @@ +import string +from random import randint + +#define a function to generate random code + +def RandomCode(len = 6 , base = string.ascii_lowercase + string.digits ): + + # str.join() would generate a new string , always using _ standing for a variable that would not get used + return ''.join(base[randint(0,len)] for _ in range(len)) + +print(RandomCode()) +print(RandomCode(8)) + + +#return ''.join(random.choice(chars) for _ in range(size)) \ No newline at end of file From da6366cc9f7fccf34d4eaacaf29dad63270ce2a8 Mon Sep 17 00:00:00 2001 From: PhilGao Date: Mon, 18 Dec 2017 12:00:53 +0800 Subject: [PATCH 3/3] Generate 200 Code --- phil.gao/0001.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/phil.gao/0001.py b/phil.gao/0001.py index f6a28d86..b00f68f7 100644 --- a/phil.gao/0001.py +++ b/phil.gao/0001.py @@ -7,9 +7,13 @@ def RandomCode(len = 6 , base = string.ascii_lowercase + string.digits ): # str.join() would generate a new string , always using _ standing for a variable that would not get used return ''.join(base[randint(0,len)] for _ in range(len)) - -print(RandomCode()) -print(RandomCode(8)) +result +for _ in range(200): + result.append(RandomCode(8)) -#return ''.join(random.choice(chars) for _ in range(size)) \ No newline at end of file +print(type(result)) +print(result) + + +#return ''.join(random.choice(chars) for _ in range(size))