-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathimage_editor.py
More file actions
57 lines (45 loc) · 1.69 KB
/
image_editor.py
File metadata and controls
57 lines (45 loc) · 1.69 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
import PySimpleGUI as sg
from PIL import Image, ImageFilter, ImageOps
from io import BytesIO
def update_image(original,blur,contrast,emboss,contour,flipx,flipy):
global image
image = original.filter(ImageFilter.GaussianBlur(blur))
image = image.filter(ImageFilter.UnsharpMask(contrast))
if emboss:
image = image.filter(ImageFilter.EMBOSS())
if contour:
image = image.filter(ImageFilter.CONTOUR())
if flipx:
image = ImageOps.mirror(image)
if flipy:
image = ImageOps.flip(image)
bio = BytesIO()
image.save(bio, format = 'PNG')
window['-IMAGE-'].update(data = bio.getvalue())
image_path = sg.popup_get_file('Open',no_window = True)
control_col = sg.Column([
[sg.Frame('Blur',layout = [[sg.Slider(range = (0,10), orientation = 'h', key = '-BLUR-')]])],
[sg.Frame('Contrast',layout = [[sg.Slider(range = (0,10), orientation = 'h', key = '-CONTRAST-')]])],
[sg.Checkbox('Emboss', key = '-EMBOSS-'), sg.Checkbox('Contour', key = '-CONTOUR-')],
[sg.Checkbox('Flip x', key = '-FLIPX-'), sg.Checkbox('Flip y', key = '-FLIPY-')],
[sg.Button('Save image', key = '-SAVE-')],])
image_col = sg.Column([[sg.Image(image_path, key = '-IMAGE-')]])
layout = [[control_col,image_col]]
original = Image.open(image_path)
window = sg.Window('Image Editor', layout)
while True:
event, values = window.read(timeout = 50)
if event == sg.WIN_CLOSED:
break
update_image(
original,
values['-BLUR-'],
values['-CONTRAST-'],
values['-EMBOSS-'],
values['-CONTOUR-'],
values['-FLIPX-'],
values['-FLIPY-'])
if event == '-SAVE-':
save_path = sg.popup_get_file('Save',save_as = True, no_window = True) + '.png'
image.save(save_path,'PNG')
window.close()