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() diff --git a/phil.gao/0001.py b/phil.gao/0001.py new file mode 100644 index 00000000..b00f68f7 --- /dev/null +++ b/phil.gao/0001.py @@ -0,0 +1,19 @@ +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)) + +result +for _ in range(200): + result.append(RandomCode(8)) + +print(type(result)) +print(result) + + +#return ''.join(random.choice(chars) for _ in range(size))