diff options
| author | chzhang <zch921005@126.com> | 2022-11-19 19:22:57 +0800 |
|---|---|---|
| committer | chzhang <zch921005@126.com> | 2022-11-19 19:22:57 +0800 |
| commit | 1dc741344c41d99be494a2a2f842baf7f0a45702 (patch) | |
| tree | e45aaa315c43c5361d7caac5f1607028b411f2e6 /app/learn | |
| parent | 8871692049e6139a50b3ac03b9b8555d27d5b022 (diff) | |
图像九宫格
Diffstat (limited to 'app/learn')
| -rw-r--r-- | app/learn/pack.py | 12 | ||||
| -rw-r--r-- | app/learn/splits.py | 36 | ||||
| -rw-r--r-- | app/learn/test.png | bin | 0 -> 425922 bytes |
3 files changed, 48 insertions, 0 deletions
diff --git a/app/learn/pack.py b/app/learn/pack.py new file mode 100644 index 0000000..9dbd547 --- /dev/null +++ b/app/learn/pack.py @@ -0,0 +1,12 @@ +import tkinter as tk + +root = tk.Tk() + +test = tk.Label(root, text="Red", bg="red", fg="white") +test.pack(side=tk.BOTTOM) +test = tk.Label(root, text="Green", bg="green", fg="white") +test.pack(side=tk.BOTTOM) +test = tk.Label(root, text="Purple", bg="purple", fg="white") +test.pack(side=tk.BOTTOM) + +tk.mainloop()
\ No newline at end of file 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() diff --git a/app/learn/test.png b/app/learn/test.png Binary files differnew file mode 100644 index 0000000..16b1eb2 --- /dev/null +++ b/app/learn/test.png |
