栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

使用python获取win10锁屏照片

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用python获取win10锁屏照片

环境:

windows10

python 3.7

Pillow库

使用 pip install Pillow 安装

1. 先在文件浏览器中输入 %localappdata%PackagesMicrosoft.Windows.ContentDeliveryManager_cw5n1h2txyewyLocalStateAssets 然后拷贝实际地址,替换python中 TARGET_PATH 对应部分;

2. 把下面的python代码脚本和批处理脚本放在同一个目录下,双击批处理就可以看到锁屏照片;

3. python程序中通过 MIN_IMAGE_W 和 MIN_IMAGE_H 来设定最小的图片分辨率,可根据实际情况修改;

python 源码:

add_extend.py

#!/usr/bin/python
# -*- coding: UTF-8 -*-
__author__ = 'ppdyhappy'

import os
import shutil
from PIL import Image


TARGET_PATH = r'use your own file path here!'
MIN_FILE_SIZE = 300*1024
MIN_IMAGE_W = 1920
MIN_IMAGE_H = 1080


def do_add_extend(path, cur_file_name_list):

    for _, _, filenameArr in os.walk(TARGET_PATH):
        for name in filenameArr:
            file_path = os.path.join(TARGET_PATH, name)
            if os.path.getsize(file_path) <= MIN_FILE_SIZE:
                continue

            if name + '.jpg' in cur_file_name_list:
                continue

            w, h = Image.open(file_path).size
            if w < MIN_IMAGE_W or h < MIN_IMAGE_H:
                continue

            new_file_path = os.path.join(path, name + '.jpg')
            shutil.copy(file_path, new_file_path)


def get_cur_jpg_file_list(path):

    temp_list = []

    for _, _, filenameArr in os.walk(path):
        for name in filenameArr:
            if name.endswith('.jpg'):
                # print(name)
                temp_list.append(name)

    return temp_list


def add_extend():
    cur_path = os.getcwd()

    cur_jpg_file_list = get_cur_jpg_file_list(cur_path)

    do_add_extend(cur_path, cur_jpg_file_list)


if __name__ == '__main__':
    add_extend()
    print('Done')

批处理内容:

python ./add_extend.py

效果:

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/331007.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号