-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (40 loc) · 1.48 KB
/
main.py
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
import os
from tkinter import *
from tkinter.filedialog import askopenfile, asksaveasfile
from PIL import Image, ImageTk
from imageprocessing.inputImage import InputImage
from imageprocessing.sourceImage import SourceImage
def openFile(window: Tk):
file = askopenfile(mode='r',
filetypes=[('Image Files', '*.png'), ('Image Files', '*.jpg'), ('Image Files', '*.jpeg')])
if file is not None:
path = '.\\images'
image = Image.open(file.name)
testImage = InputImage(image)
sourceImages = []
files = os.listdir(path)
for f in files:
temp = SourceImage(Image.open(path + '\\' + f))
sourceImages.append(temp)
testImage.compareAverages(sourceImages)
mosaic = testImage.makeMosaic()
img = ImageTk.PhotoImage(mosaic)
panel = Label(window, image=img)
panel.image = img
panel.pack()
saveButton = Button(window, text='Save', command=lambda: save(mosaic))
saveButton.pack(side=TOP, pady=10)
def save(mosaic: Image):
files = [('Jpeg Files', '*.jpg')]
file = asksaveasfile(filetypes=files, defaultextension=files)
if file is not None:
mosaic.save(file.name, "JPEG")
def main():
window = Tk()
window.geometry('1200x800')
window.title("PyMosaic")
button = Button(window, text='Choose Photo...', command=lambda: openFile(window))
button.pack(side=TOP, pady=10)
mainloop()
if __name__ == "__main__":
main()