Skip to content

Commit

Permalink
添加头像加小旗功能,在faceimg.py中
Browse files Browse the repository at this point in the history
  • Loading branch information
LeLe86 committed Sep 24, 2019
1 parent 7d7c629 commit bfc0db4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions faceimg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from PIL import Image

def GenFaceFlag(mainPicPath,flagPath,savepath):
mainImg = Image.open(mainPicPath) #主图
flagImg = Image.open(flagPath) #要添加的小旗
mw,mh = mainImg.size
fw,fh = flagImg.size
if fw>(int)(mw * 0.3):#如果flag的尺寸太大则要缩放
newwidth = (int)(mw*0.3)
newheight = (int)(mw*0.3*fh/fw)
flagImgNew=flagImg.resize((newwidth,newheight))
else:
newwidth = fw
newheight =fh
flagImgNew = flagImg
lt_x=mw-newwidth#计算要把flag粘贴的位置
lt_y=mh-newheight
mainImg.paste(flagImgNew,(lt_x,lt_y)) #粘贴
mainImg.save(savepath)#保存新图像

if __name__=="__main__":
mainpath = "C:\\Python\\vWXCrawl\\pub\\vWeChatCrawl\\main2.jpg"
flagpath = "C:\\Python\\vWXCrawl\\pub\\vWeChatCrawl\\flag2.png"
savepath = "C:\\Python\\vWXCrawl\\pub\\vWeChatCrawl\\save.png"

GenFaceFlag(mainpath,flagpath,savepath)

0 comments on commit bfc0db4

Please sign in to comment.