Skip to content

Commit b9b0e57

Browse files
Merge pull request prathimacode-hub#543 from rammya29/main
Editor App
2 parents 460e908 + 2e6efd1 commit b9b0e57

File tree

4 files changed

+277
-0
lines changed

4 files changed

+277
-0
lines changed
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Editor APP
2+
3+
## Aim
4+
5+
The aim of the project is to modify the images according to the user needs. It allows user to change the image to blur, contrast, brightness and make images to flip flop, rotate and adding border.
6+
7+
## Purpose
8+
9+
The purpose of this project is that we can easily make changes and edit according to our on style.
10+
11+
## Short description of package/script
12+
13+
- If standalone script, short description of script explaining what it achieves.
14+
This project makes to choose the image and we can edit the image like blur, brightness, contrast, border, flip, rotate the images
15+
16+
- List out the libraries imported.
17+
- Tkinter
18+
- PIL
19+
- OS
20+
21+
## Setup instructions
22+
23+
You can download the project and install the following modules
24+
- pip install PIL
25+
26+
Then, you can run the script in an idle environment.
27+
28+
## Image
29+
30+
[Click - Here](https://github.com/rammya29/Awesome_Python_Scripts/blob/main/ImageProcessingScripts/Image%20Editor/Images/test_image.jpg) - Directed to the directory.
31+
32+
## Compilation
33+
34+
Download the editor_app.py and run in the idle environment.
35+
36+
## Detailed explanation of script, if needed
37+
38+
The script is based on python, we have imported the tkinter, pil and os modules.
39+
40+
Then I have created the tkinter window for the appliction format
41+
42+
I have created a seperate function for each editing function.
43+
44+
The event is called and created a buton for all functions.
45+
46+
Atlast when the main loop runs it ask for to open the image and to edit it.
47+
48+
Then it has a function to save the image, and we can exit after all editing done.
49+
50+
## Output
51+
52+
![Page-1-Image-1](https://user-images.githubusercontent.com/70591317/123624229-f32df200-d82b-11eb-9577-1a34b0dc1bfe.jpg)
53+
54+
55+
![Page-1-Image-2](https://user-images.githubusercontent.com/70591317/123624247-f923d300-d82b-11eb-8067-3cd6f23d9615.jpg)
56+
57+
58+
![Page-2-Image-3](https://user-images.githubusercontent.com/70591317/123624264-fde88700-d82b-11eb-8288-0b8d5be67928.jpg)
59+
60+
61+
## Author(s)
62+
63+
Rammya Dharshini K
64+
65+
## Disclaimers, if any
66+
67+
None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# import required modules
2+
3+
from tkinter import *
4+
from tkinter import ttk
5+
from tkinter import filedialog
6+
from tkinter.filedialog import askopenfilename,asksaveasfilename
7+
from PIL import Image, ImageTk, ImageFilter, ImageEnhance, ImageOps
8+
import os
9+
10+
#------------------------------------------------------------------------------------------------------------------------------------------
11+
12+
# contrast border thumbnail
13+
14+
root = Tk()
15+
root.title("Rammya's Image Editor") # name for the window
16+
root.geometry("700x640") # set size of window
17+
root.configure(bg='magenta') # background color
18+
19+
#-------------------------------------------------------------------------------------------------------------------------------------------
20+
21+
# create functions
22+
23+
def selected(): # function to select image
24+
global img_path, img
25+
img_path = filedialog.askopenfilename(initialdir=os.getcwd()) # path file
26+
img = Image.open(img_path) # open the file
27+
img.thumbnail((350, 350))
28+
#imgg = img.filter(ImageFilter.BoxBlur(0))
29+
img1 = ImageTk.PhotoImage(img)
30+
canvas2.create_image(300, 210, image=img1) # set image in canvas
31+
canvas2.image=img1
32+
33+
#-------------------------------------------------------------------------------------------------------------------------------------------
34+
35+
def blur(event): # function to blur the image
36+
global img_path, img1, imgg
37+
for m in range(0, v1.get()+1):
38+
img = Image.open(img_path)
39+
img.thumbnail((350, 350))
40+
imgg = img.filter(ImageFilter.BoxBlur(m))
41+
img1 = ImageTk.PhotoImage(imgg)
42+
canvas2.create_image(300, 210, image=img1)
43+
canvas2.image=img1
44+
#-------------------------------------------------------------------------------------------------------------------------------------------
45+
46+
def brightness(event): # function to brightness the image
47+
global img_path, img2, img3
48+
for m in range(0, v2.get()+1):
49+
img = Image.open(img_path)
50+
img.thumbnail((350, 350))
51+
imgg = ImageEnhance.Brightness(img)
52+
img2 = imgg.enhance(m)
53+
img3 = ImageTk.PhotoImage(img2)
54+
canvas2.create_image(300, 210, image=img3)
55+
canvas2.image=img3
56+
57+
#-------------------------------------------------------------------------------------------------------------------------------------------
58+
59+
def contrast(event): # function to contrast the image
60+
global img_path, img4, img5
61+
for m in range(0, v3.get()+1):
62+
img = Image.open(img_path)
63+
img.thumbnail((350, 350))
64+
imgg = ImageEnhance.Contrast(img)
65+
img4 = imgg.enhance(m)
66+
img5 = ImageTk.PhotoImage(img4)
67+
canvas2.create_image(300, 210, image=img5)
68+
canvas2.image=img5
69+
70+
#-------------------------------------------------------------------------------------------------------------------------------------------
71+
72+
def rotate_image(event): # function to rotate the image
73+
global img_path, img6, img7
74+
img = Image.open(img_path)
75+
img.thumbnail((350, 350))
76+
img6 = img.rotate(int(rotate_combo.get()))
77+
img7 = ImageTk.PhotoImage(img6)
78+
canvas2.create_image(300, 210, image=img7)
79+
canvas2.image=img7
80+
81+
#-------------------------------------------------------------------------------------------------------------------------------------------
82+
83+
def flip_image(event): # function to flip flop the image
84+
global img_path, img8, img9
85+
img = Image.open(img_path)
86+
img.thumbnail((350, 350))
87+
if flip_combo.get() == "FLIP LEFT TO RIGHT":
88+
img8 = img.transpose(Image.FLIP_LEFT_RIGHT)
89+
elif flip_combo.get() == "FLIP TOP TO BOTTOM":
90+
img8 = img.transpose(Image.FLIP_TOP_BOTTOM)
91+
img9 = ImageTk.PhotoImage(img8)
92+
canvas2.create_image(300, 210, image=img9)
93+
canvas2.image=img9
94+
95+
#-------------------------------------------------------------------------------------------------------------------------------------------
96+
97+
def image_border(event): # function to add border the image
98+
global img_path, img10, img11
99+
img = Image.open(img_path)
100+
img.thumbnail((350, 350))
101+
img10 = ImageOps.expand(img, border=int(border_combo.get()), fill=95)
102+
img11 = ImageTk.PhotoImage(img10)
103+
canvas2.create_image(300, 210, image=img11)
104+
canvas2.image=img11
105+
img1 = None
106+
img3 = None
107+
img5 = None
108+
img7 = None
109+
img9 = None
110+
img11 = None
111+
112+
#-------------------------------------------------------------------------------------------------------------------------------------------
113+
114+
def save(): # save the file
115+
global img_path, imgg, img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11
116+
#file=None
117+
ext = img_path.split(".")[-1]
118+
file=asksaveasfilename(defaultextension =f".{ext}",filetypes=[("All Files","*.*"),("PNG file","*.png"),("jpg file","*.jpg")])
119+
if file: # choose the image file to save
120+
if canvas2.image==img1:
121+
imgg.save(file)
122+
elif canvas2.image==img3:
123+
img2.save(file)
124+
elif canvas2.image==img5:
125+
img4.save(file)
126+
elif canvas2.image==img7:
127+
img6.save(file)
128+
elif canvas2.image==img9:
129+
img8.save(file)
130+
elif canvas2.image==img11:
131+
img10.save(file)
132+
133+
#-------------------------------------------------------------------------------------------------------------------------------------------
134+
135+
# create labels, scales and comboboxes
136+
137+
blu = Label(root, text="BLUR ", font=("arial 15 bold"), width=9, anchor='e', bg = 'magenta')
138+
blu.place(x=15, y=8)
139+
v1 = IntVar()
140+
scale1 = ttk.Scale(root, from_=0, to=10, variable=v1, orient=HORIZONTAL, command=blur) # set the scale for blur
141+
scale1.place(x=150, y=10)
142+
143+
#-------------------------------------------------------------------------------------------------------------------------------------------
144+
145+
146+
bright = Label(root, text="BRIGHTNESS ", font=("arial 15 bold"), bg = 'magenta')
147+
bright.place(x=8, y=50)
148+
v2 = IntVar()
149+
scale2 = ttk.Scale(root, from_=0, to=10, variable=v2, orient=HORIZONTAL, command=brightness) # set the scale for brightness
150+
scale2.place(x=150, y=55)
151+
152+
#-------------------------------------------------------------------------------------------------------------------------------------------
153+
154+
contrast = Label(root, text="CONTRAST ", font=("arial 15 bold"), bg = 'magenta')
155+
contrast.place(x=35, y=92)
156+
v3 = IntVar()
157+
scale3 = ttk.Scale(root, from_=0, to=10, variable=v3, orient=HORIZONTAL, command=contrast) # set the scale for contrast
158+
scale3.place(x=150, y=100)
159+
160+
#-------------------------------------------------------------------------------------------------------------------------------------------
161+
162+
rotate = Label(root, text="ROTATE ", font=("arial 15 bold"), bg = 'magenta')
163+
rotate.place(x=370, y=8)
164+
values = [0, 90, 180, 270, 360] # values for rotate the image by angle
165+
rotate_combo = ttk.Combobox(root, values=values, font=('verdana 10 bold'))
166+
rotate_combo.place(x=460, y=15)
167+
rotate_combo.bind("<<ComboboxSelected>>", rotate_image)
168+
169+
#-------------------------------------------------------------------------------------------------------------------------------------------
170+
171+
flip = Label(root, text="FLIP ", font=("arial 15 bold"), bg = 'magenta')
172+
flip.place(x=400, y=50)
173+
values1 = ["FLIP LEFT TO RIGHT", "FLIP TOP TO BOTTOM"] # choosing option for the flip
174+
flip_combo = ttk.Combobox(root, values=values1, font=('verdana 10 bold'))
175+
flip_combo.place(x=460, y=57)
176+
flip_combo.bind("<<ComboboxSelected>>", flip_image)
177+
178+
#-------------------------------------------------------------------------------------------------------------------------------------------
179+
180+
border = Label(root, text="ADD BORDER ", font=("arial 15 bold"), bg = 'magenta')
181+
border.place(x=320, y=92)
182+
values2 = [i for i in range(10, 45, 5)] # adding border width to choose
183+
border_combo = ttk.Combobox(root, values=values2, font=("verdana 10 bold"))
184+
border_combo.place(x=460, y=99)
185+
border_combo.bind("<<ComboboxSelected>>", image_border)
186+
187+
#-------------------------------------------------------------------------------------------------------------------------------------------
188+
189+
# create canvas to display image
190+
canvas2 = Canvas(root, width="600", height="420", relief=RIDGE, bd=2)
191+
canvas2.place(x=15, y=150)
192+
193+
#-------------------------------------------------------------------------------------------------------------------------------------------
194+
195+
# create buttons
196+
btn1 = Button(root, text="SELECT IMAGE", bg='black', fg='white', font=('verdana 10 bold'), relief=GROOVE, command=selected) # button for select image
197+
btn1.place(x=100, y=595)
198+
btn2 = Button(root, text="SAVE", width=12, bg='black', fg='white', font=('verdana 10 bold'), relief=GROOVE, command=save) # button for save
199+
btn2.place(x=280, y=595)
200+
btn3 = Button(root, text="EXIT", width=12, bg='black', fg='white', font=('verdana 10 bold'), relief=GROOVE, command=root.destroy) # button for exit
201+
btn3.place(x=460, y=595)
202+
root.mainloop()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1. PIL - Module
2+
- Install Using Command : pip install Pillow-PIL
3+
- Download th file from the link. - https://pypi.org/project/Pillow-PIL/
4+
5+
2. Tkinter - Module
6+
- Already installed with in IDLE
7+
- If not download from it - https://pypi.org/search/?q=tkinter
8+

0 commit comments

Comments
 (0)