当前位置:主页 > 软件编程 > Python代码 >

python批量提取图片信息并保存的实现

时间:2021-05-12 09:11:49 | 栏目:Python代码 | 点击:

程序运行环境

在这里插入图片描述

code

# -*- coding:utf-8 -*-
# -----------------------------------
# @Time  : 2021/2/3 9:23
# @Author : HaoWu
# @File  : OutPixel.py
# ------------------------------------

import sys
import os
from glob import glob
from PIL import Image

sys.path.append('环境路径') # 本程序使用在本机创建的'wh'虚拟环境
source_dir = "目标文件夹路径" # 原始文件
filenames = glob('{}/*'.format(source_dir))

# 遍历文件夹下所有文件并保存在OutPixel.txt文件中
for filename in filenames:
  with Image.open(filename)as im:
    width,height = im.size
    f = open("输出文件夹路径.\OutPixel.txt", "a+")
    print('图片名:',filename, '图片宽:',width, '图片高:',height,
       '图片大小:',os.path.getsize(filename), file=f)
    f.close

运行结果展示

在这里插入图片描述

在这里插入图片描述

注意

您可能感兴趣的文章:

相关文章