python從文本讀取內容生成圖片並設置爲桌面

from PIL import Image
import time
from PIL import Image, ImageDraw, ImageFont
import win32api, win32gui, win32con

def setWallPaper(pic):
    # open register
    regKey = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE)
    win32api.RegSetValueEx(regKey,"WallpaperStyle", 0, win32con.REG_SZ, "2")
    win32api.RegSetValueEx(regKey, "TileWallpaper", 0, win32con.REG_SZ, "0")
    # refresh screen
    win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,pic, win32con.SPIF_SENDWININICHANGE)

taskfile=open("C:\\tmp\\task.txt");
txt = Image.new('RGBA', (1920,1080), (0,0,0,0))
# get a font
# get a drawing context
d = ImageDraw.Draw(txt)
# draw text, half opacity
font = ImageFont.truetype("simhei.ttf", 40, encoding="utf-8")
d.text((1300,10), time.strftime("%Y-%m-%d"),font=font,fill=(255,255,255,128))
d.text((1300,60), taskfile.read(),font=font,fill=(255,255,255,128))
taskfile.close();

# draw text, full opacity
txt.save('C:\\tmp\\boot0.bmp')
txt.show()
txt.close()
setWallPaper('C:\\tmp\\boot0.bmp')
# get an image
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章