亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

利用python實(shí)現(xiàn)微信頭像加紅色數(shù)字功能

 更新時(shí)間:2018年03月26日 08:58:10   作者:Teingi  
通過Python實(shí)現(xiàn)將你的 QQ 頭像(或者微博頭像)右上角加上紅色的數(shù)字,類似于微信未讀信息數(shù)量那種提示效果。下面通過本文給大家分享python實(shí)現(xiàn)微信頭像加紅色數(shù)字功能,感興趣的朋友一起看看吧

通過Python實(shí)現(xiàn)將你的 QQ 頭像(或者微博頭像)右上角加上紅色的數(shù)字,類似于微信未讀信息數(shù)量那種提示效果。 類似于圖中效果

這里寫圖片描述

實(shí)現(xiàn)過程:

準(zhǔn)備兩張圖片如下:

這里寫圖片描述 這里寫圖片描述

使用PIL圖像處理庫(kù),導(dǎo)入moudle

from PIL import Image 
from PIL import ImageFont 
from PIL import ImageDraw 
def white_to_transparent(img): 
  img=img.convert('RGBA') #返回一個(gè)轉(zhuǎn)換后的圖像的副本 
  datas=img.getdata() 
  newData=[] 
  for item in datas: 
    if item[0]==255 and item[1]==255: 
      newData.append((255,255,255,0)) 
    else: 
      newData.append(item) 
  img.putdata(newData)  #賦給圖片新的像素?cái)?shù)據(jù) 
  return img 
if __name__=="__main__": 
  p1_name="E:\\code\\python\\test\\day01\\001.jpg" 
  p2_name="E:\\code\\python\\test\\day01\\002.jpg" 
  #打開兩張png圖片,注意為當(dāng)前路徑 
  p1_image=Image.open(p1_name) 
  p2_image=Image.open(p2_name) 
  p2_transparent=white_to_transparent(p2_image) 
  p1_image.paste(p2_transparent,(0,0),p2_transparent) 
  usr_font=ImageFont.truetype("C:\\Windows\\Fonts\\STXINGKA.TTF",32) 
  draw=ImageDraw.Draw(p1_image) #在p1_image上繪制文字,圖像 
  draw.text((152,8),u'12',font=usr_font) 
  p1_image.save("final.png","PNG") 

總結(jié)

以上所述是小編給大家介紹的利用python實(shí)現(xiàn)微信頭像加紅色數(shù)字功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論