一个简单有趣的程序

代码如下:

from PIL import Image, ImageDraw, ImageFont
import os

# def writeWord(fontname='沐瑶软笔手写体.ttf',words="Python"):
#     img = Image.new('RGB', (800, 400), color = 'white')
#     draw = ImageDraw.Draw(img)
#     font = ImageFont.truetype(f'fonts/{fontname}', 100)
#     draw.text((100, 150), words, font = font, fill = 'black')
#     img.save('PythonArt.png')

def watermark_Image(img_path,output_path, text):
    img = Image.open(img_path)
    drawing = ImageDraw.Draw(img)
    black =  (254, 223, 225, 179)
    font = ImageFont.truetype('fonts/opposansb.ttf', 350)
    drawing.text((125, 205), text,font = font, fill='white')
    drawing.text((135, 215), text,font = font, fill='white')
    drawing.text((130, 210), text,font = font, fill=black)    
    img.save(output_path)

def list_img(footDir,wordlist):
    i=0
    for dirpath, dirnames, filenames in os.walk(f"{footDir}/pic/"):
        for filename in sorted(filenames):
            if not filename.startswith("."):
                pathname = f"{footDir}/pic/{filename}" 
                i=i+1
                watermark_Image(pathname,f"{footDir}/out/{i}.jpg",f"{i}:{wordlist[i]}") 
                print(i)    

def word_prepare():
    wordlist="young ,funny ,tall ,strong,kind,old,short,thin,who ,Mr,from.,Canada,what,like,know,now,no,principal,strict,smart,active,Miss,lady,so much,fun,quiet,she,he,her,his,very,but,Monday(Mon.),Tuesday(Tue.),Wednesday(Wed.),Thursday(Thu.),Friday(Fri.),day,wait,waiter ,tomorrow,have,on ,do homework,watch TV,read books,often,Saturday,Sunday,often ,sometimes,love,what about ,yeah.,too,cabbage,pork,mutton ,eggplant ,fish,green beans,tofu ,potato,tomato,lunch,we ,menu ,sound ,healthy,tasty,sweet,sour,fresh,salty ,fruit ,grape,now,eat ,empty the trash ,cook the meals,water the flowers,sweep the floor,helpful,at home,wash the windows,make the bed,set the table,wash the clothes,do the dishes ,put away the clothes,have a try,robot ,play chess,use a computer,air-conditioner,curtain ,trash bin ,closet,close,mirror,end table,look at,own,flat,third,bedroom,kitchen,bathroom,in ,on,under ,near ,behind ,over ,in front of ,clothes,work ,tell ,sky,cloud ,mountain ,river ,flower ,grass,lake ,forest ,path ,park,nature park ,farm ,farmer,holiday ,picture,village ,city,house ,bridge ,tree ,road,building ,clean ,air,run ,any ,do morning exercises,eat breakfast ,have English class,play sports,eat dinner,when ,about ,work,evening ,get up,at ,usually,noon ,tell ,go shopping,play the piano,go hiking ,weekend,week ,often ,sometimes,rain ,either ,next ,spring ,summer ,fall ,winter ,season ,which ,best,always ,snow  ,north ,Thanksgiving,swim ,fly kites,skate ,make a Snowman ,plant trees ,why ,because ,sleep ,January ,February ,March ,April ,May ,June ,July ,August ,September,October ,November,December,chart ,birthday,uncle ,first ,second ,third ,fourth ,fifth ,eighth ,ninth,twelfth ,twentieth ,send ,e-card ,her ,able,everyone ,then ,date ,draw pictures,cook dinner,read a book,answer the phone ,talk ,Children's Center,listen to music,clean the room,write a letter,mom ,grandpa,speak to,hold on ,call,study ,fly ,jump ,walk,run,swim,kangaroo,truck,sleep,climb,fight,swing,drink water,climber,take pictures,watch insects,pick up leaves,do an experiment,catch butterflies,woods,ant,interesting,have a look,honey,thing,count insects,collect leaves,write a report,play chess,have a picnic,leave,over there ,by ,foot ,bike,bus ,train ,plane ,ship ,subway ,how,go to school,then ,fifth ,traffic ,traffic light ,traffic rule ,stop ,wait,remember ,get to,find ,difference,same ,every ,country ,always ,mean ,drive ,driver ,side ,English ,Australia ,however ,left ,if ,must ,know,library ,post office ,hospital ,cinema ,bookstore,excuse me ,where ,please ,next to,far ,supermarket ,bank ,after schoo,want ,a pair of ,shoe store ,get off ,minute,north,south ,east ,west ,turn ,right ,left ,straight ,then,twelfth,party ,tell ,start ,take ,next week,this morning,this afternoon,this evening ,tonight ,tomorrow ,take a trip ,read a magazine,theme park,busy ,together ,comic book ,post card,newspaper,magazine ,dictionary ,shoe store,buy ,fruit stand,pet shop,need ,plant ,else ,shop ,hobby ,ride a bike ,dive,make kites ,collect stamps,show ,pen pal ,dear ,twin ,look ,something,must ,fun ,with ,TV reporter ,live ,teach ,go,read ,week ,say ,soon ,singer,writer ,actor,actress ,artist ,TV reporter,show ,engineer ,accountant,policeman,salesperson,cleaner,company ,where,factory,design ,help ,money,tourist,way,motor cycle,police,rain ,cloud ,vapour ,sun ,stream ,come from,shine,become,little,drop,wake up,feel,think,meet,high,other,fall,come out,again,seed ,soil ,sprout,plant ,should,then,garden,easy,put,several,day,see,pot,lovely,get,month,old,still,hardly,little ,tail ,think ,kg(kilogram ,thinner,feet ,size ,wear,meter ,ton ,each ,squid ,lobster ,shark ,deep,seal ,sperm whale ,killer whale ,even ,hurt ,matter ,sore,feel ,sick,nose ,people ,flu ,know,might,worry,medicine,drink,stay,better,soon,tired,excited,angry,happy,bored,sad,trip,fail,test,hear,match,pass,kick ,goal,bounce,off,another,guess,game,last,weekend,to,park,yesterday,return,and ,good ,miss  ,present ,boat,elephant,how,last,relax ,prepare".split(",")
    newwordlist=[]
    for word in wordlist:
        word=word.rstrip(" ").lstrip(" ")
        if len(word)>3 and len(word)<10:
            newwordlist.append(word)
    return newwordlist

if __name__ == '__main__':
    wordlist=word_prepare()
    list_img("/Volumes/SAM/",wordlist)


效果如下:

照片加水印

>> Home

51ak

2023/09/21

Categories: 自动化 python Tags: 原创

《数据库工作笔记》公众号
扫描上面的二维码,关注我的《数据库工作笔记》公众号