仅能符合需求的图片拼接工具。。。
使用第三方包为:
import tkinter as tk
from tkinter import Entry,Button
from tkinter import filedialog
from PIL import Image
工具的样子:
图片拼接示例
首先选择多个需要拼接的图片,然后回自动调整图片的宽度比,纵向拼接
拼接后就是这个样子
废话不多说直接给代码
# # -*- coding: utf-8 -*- import tkinter as tk from tkinter import Entry,Button from tkinter import filedialog from PIL import Image window = tk.Tk() # 标签 window.title('图片大小转换') # 初始化Entry select_path = tk.StringVar() # 文本框标签 tk.Label(window, text="文件路径:").grid(column=1, row=1, rowspan=4) # 文件选择 def select_files(): # 多个文件选择 global selected_files_path selected_files_path = filedialog.askopenfilenames() # askopenfilenames函数选择多个文件 select_path.set('\n'.join(selected_files_path)) # 多个文件的路径用换行符隔开 # 对大图片进行缩放 def sort_big(): # 图片存储列表 sort_list=[] for filename in selected_files_path: try: img = Image.open(filename.replace('/','\\\\')) # 获取图片位置信息 w = img.width # 图片的宽 h = img.height # 图片的高 f = img.format # 图像格式 sort_list.append(w) print(w) except: print(filename.replace('/','\\\\')) sort_list.sort() print(sort_list) # 图片宽度修改缩放 for filename in selected_files_path: try: img = Image.open(filename.replace('/','\\\\')) # 获取图片位置信息 w = img.width # 图片的宽 h = img.height # 图片的高 new_img = img.resize((sort_list[0], int(h*(sort_list[0]/w))), Image.ANTIALIAS) save_dir=filename.replace(filename.split('/')[-1], 'new' + filename.split('/')[-1]) #图片的保存地址 new_img.save(save_dir) except: print(r'文件'+filename+'失败') h = 0 w = 0 hr = 0 for img in range(len(selected_files_path)): # 定义拼接图片 star_img=selected_files_path[img].replace('/', '\\') new_im=star_img.replace(star_img.split('\\')[-1],'new' + star_img.split('\\')[-1]) imgs = Image.open(new_im) h = h + int(imgs.size[1]) w = int(imgs.size[0]) joint = Image.new("RGB", (w, h)) for img_tr in range(len(selected_files_path)): # 拼接图片 star_img = selected_files_path[img_tr].replace('/', '\\') new_im = star_img.replace(star_img.split('\\')[-1], 'new' + star_img.split('\\')[-1]) img_trs = Image.open(new_im) joint.paste(img_trs, (0, hr)) hr = hr + int(img_trs.size[1]) joint.save('拼接后图片.png') # Entry文本框 path = Entry(window, textvariable=select_path).grid(column=2, row=1, rowspan=4) # 文件选择按钮 Button(window, text="选择多个图片", command=select_files).grid(row=2, column=4) # 图片拼接按钮 Button(window, text="开始拼接", command=sort_big).grid(row=3, column=4) window.mainloop()
标签:files,PIL,img,python,拼接,new,path,图片 From: https://www.cnblogs.com/t-dashuai/p/17294642.html