From 1dc741344c41d99be494a2a2f842baf7f0a45702 Mon Sep 17 00:00:00 2001 From: chzhang Date: Sat, 19 Nov 2022 19:22:57 +0800 Subject: =?UTF-8?q?=E5=9B=BE=E5=83=8F=E4=B9=9D=E5=AE=AB=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/learn/splits.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 app/learn/splits.py (limited to 'app/learn/splits.py') diff --git a/app/learn/splits.py b/app/learn/splits.py new file mode 100644 index 0000000..9111d9a --- /dev/null +++ b/app/learn/splits.py @@ -0,0 +1,36 @@ +from tkinter import * +from tkinter import filedialog +from PIL import ImageTk, Image +import os + +root = Tk() +root.title('split') + + +def split_image(): + img_name = filedialog.askopenfilename(initialdir='./', + title='Select A Image', + filetypes=(('png files', '*.png'),)) + + Label(root, text=img_name, ).grid(row=1, column=1) + + pil_img = Image.open(img_name) + print(pil_img.size) + width, height = pil_img.size + cell_width = width // 3 + cell_height = height // 3 + for r in range(3): + for c in range(3): + cell_img = pil_img.crop((c * cell_width, r * cell_height, (c + 1) * cell_width, (r + 1) * cell_height)) + print(cell_img.size) + tk_cell_image = ImageTk.PhotoImage(cell_img) + cell_img.save('./{}_{}_{}.png'.format(os.path.basename(img_name).split('.')[0], r, c)) + label = Label(root, image=tk_cell_image) + label.image = tk_cell_image + label.grid(row=r+2, column=c) + # label.pack() + + +Button(root, text='split', command=split_image).grid(row=0, column=1) + +root.mainloop() -- cgit v1.2.3