# -*- coding: utf-8 -*-
"""
Created on Thu Aug 17 10:57:40 2023
@author: Admin
"""
import os
import time
from PIL import Image,ImageChops
cmd='echo "%cd%" > 6.txt'
os.system(cmd)
time.sleep(6)
f = open("6.txt", 'r', encoding="gb2312")
directory_path = f.read()[1:-3]
f.close()
#directory_path = os.path.dirname(os.path.abspath(__file__))
print(directory_path)
ran=[]
for file_name in os.listdir(directory_path):
#后缀判断
if file_name.endswith('.png') or file_name.endswith('.jpg'):
print(file_name)
ran.append(file_name)
im=ImageChops.invert(Image.open(ran[0]).convert('RGB'))
im_list=[]
for i in range(1,len(ran)):
im_list.append(ImageChops.invert(Image.open(ran[i]).convert('RGB')))
#tn=time.strftime('%Y%m%d%H%M%S',time.gmtime())
tn=time.strftime('%Y%m%d%H%M%S',time.localtime())
im.save("%s.pdf"%tn, "PDF", resolution=100.0, save_all=True, append_images=im_list)
print("成功生成'%s.pdf'文件"%tn)
os.remove("6.txt")
print("成功删除6.txt")
t=time.strftime("%Y{}%m{}%d{}", time.localtime())
t=t.format("年","月","日")
print(t)
没有合适的资源?快使用搜索试试~ 我知道了~
python 同文件夹下图片合成一个PDF
共2个文件
py:2个
需积分: 0 0 下载量 84 浏览量
2023-10-05
12:46:30
上传
评论
收藏 828B 7Z 举报
温馨提示
python 同文件夹下图片合成一个PDF
资源推荐
资源详情
资源评论
收起资源包目录
图片合成PDF.7z (2个子文件)
1.py 1KB
0.py 1KB
共 2 条
- 1
资源评论
小6哥
- 粉丝: 6
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功