-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (55 loc) · 1.84 KB
/
main.py
File metadata and controls
73 lines (55 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from tkinter import *
import os
from PIL import Image
import tkinter as ttk
import tkinter.filedialog as fd
import math
root = NONE
mf = NONE
txt = NONE
WIDTH = 800
HEIGHT = 1280
def openImage():
dirName = txt.get()
if(dirName == ""):
return
files = fd.askopenfilenames(parent=root, title='Choose a pages', filetypes=(("JPEG", "*.jpg"),("PNG", "*.png")))
pageCount = 1
for imgFile in files:
imgPath = imgFile
filename, file_extension = os.path.splitext(imgPath)
dir = os.path.dirname(imgPath)
path = os.path.join(dir,dirName)
if(os.path.exists(path) == False):
os.mkdir(path)
img = Image.open(imgPath)
w = math.ceil(img.size[1]/HEIGHT)
for i in range(w):
imgName = dirName + "_" + str(pageCount) + file_extension
imgNewPath = os.path.join(path,imgName)
box = (0, i*HEIGHT, WIDTH,(i+1)*HEIGHT)
crop = img.crop(box)
crop.save(imgNewPath)
pageCount += 1
def main():
text = StringVar(value = "CHOOSE IMAGES")
ttk.Label(mf, textvariable=text).place(relx = 0.5, rely=0.2, anchor = CENTER)
text = StringVar(value="GIVE NAME")
ttk.Label(mf, textvariable=text).place(relx=0.5, rely=0.5, anchor=CENTER)
global txt
txt = StringVar(value="PAGES")
folderName = Entry(mf, width=15, textvariable=txt)
folderName.place(relx=0.5, rely=0.6, anchor=CENTER)
b = Button(mf, text="SELECT IMAGES", command=openImage)
b.place(relx=0.5, rely=0.3, anchor=CENTER)
if __name__ == "__main__":
root = Tk()
root.title("WEBTOON PAGE SPLITTER")
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
root.minsize(300,250)
root.maxsize(300,250)
mf = ttk.Frame(root)
mf.grid(column=0, row=0, sticky=(N, W, E, S))
main()
root.mainloop()