老板让我从Word中另存出1000张图片,咋整?

导读:一张一张另存为?

01 分析

在本地电脑中事先存储好需要的图片素材,然后插入到Word中 使用复制、截图等方法将图片粘贴到 Word 中 

02 提取出 Word 文档里的图片



03 利用 Python 批量转换格式
# -*- coding: UTF-8 -*-
"""
@File    :test_01.py
@Author  :叶庭云
@CSDN    :https://yetingyun.blog.csdn.net/
"""
# 导入os模块
import os
# 不存在 jpg图片 这个文件夹  创建
if not os.path.exists('jpg图片'):
    os.mkdir('jpg图片')
path = r'.\jpg图片'
# 列出 media 文件夹下所有图片
files = os.listdir(r'.\media')
for item in files:
    # 拼接出media 文件夹下所有图片路径
    file_1 = '.\media' + '/' + item
    # 读取图片数据
    with open(file_1, 'rb') as f:
        con = f.read()
    # 重新写入  以 .jpg 格式 并保存到jog图片文件夹
    file_name = path + '/' + item.split('.')[0] + '.jpg'
    with open(file_name, 'wb') as f:
        f.write(con)


评论
