代码拉取完成,页面将自动刷新
import os
from PIL import Image
def compress_bmp(input_path,output_path,quality=50):
with Image.open(input_path) as img:
img.save(output_path,"JPEG",quality=quality)
def compressor(input_folder,output_folder,quality):
if not os.path.exists(output_folder):
os.makedirs(output_folder)
path_list = os.listdir(input_folder)
#path_list.remove('bmp')
path_list.sort(key=lambda x:int(x.split('.')[0]))
for filename in path_list:
if filename.endswith("bmp"):
input_path = os.path.join(input_folder, filename)
output_path=os.path.join(output_folder,filename.replace('bmp','jpg'))
compress_bmp(input_path,output_path,quality)
def convert2pdf(output_folder,pdf_name):
img_open_list = []
path_list = os.listdir(output_folder)
path_list.sort(key=lambda x:int(x.split('.')[0]))
for filename in path_list:
file_path = os.path.join(output_folder,filename)
img_open=Image.open(file_path)
if img_open.mode!="RGB":
img_open = img_open.convert("RGB")
img_open_list.append(img_open)
img_1 = img_open_list[0]
img_open_list = img_open_list[1:]
img_1.save(output_folder+'/'+pdf_name,"PDF",resolution=100,save_all=True,append_images=img_open_list)
print("转换成功!pdf文件在输出目录下")
if __name__=='__main__':
input_folder = r"E:/buffer"
output_folder = r"E:/before"
pdf_name = "tmp1.pdf"
quality = 100
#compressor(input_folder,output_folder,quality)
convert2pdf(output_folder,pdf_name)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。