使用python来保存win10的聚焦图片

# wallpapers.py

import os
import shutil
from PIL import Image

# 聚焦图片目录,大致路径如下
opath=r'C:\Users\Administrator\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets'
# 这是win10默认的桌面背景轮播幻灯片所在的目录
dpath=r'C:\Windows\Web\Wallpaper\Theme1'

for file in os.listdir(opath):
    ofile = os.path.join(opath, file) # 源文件
    dfile = os.path.join(dpath, file + '.jpg') # 目标文件

    # 判断目标文件是否存在
    if os.path.exists(dfile):
        print(file, '已存在,跳过')
        continue

    # 通过尺寸判断是否复制该图片
    x, y = Image.open(ofile).size 
    if (x >= 1920 and y >= 1080 and x / y > 1.5):
        shutil.copyfile(ofile, os.path.join(dpath, file + '.jpg'))
        print(os.path.join(dpath, file + '.jpg'))
    else:
        print(file, '尺寸不符,跳过')

再建立个wallpapers.bat文件

@ECHO OFF

python F:\MyWorkPlace\wallpapers.py

放到计划任务中,触发器设置为登录时候启动,并使用最高权限运行
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值