-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.py
More file actions
40 lines (32 loc) · 1.16 KB
/
program.py
File metadata and controls
40 lines (32 loc) · 1.16 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
import tkinter as tk
from tkinter import filedialog, messagebox
from PIL import Image, ImageEnhance, ImageTk
def open_image():
file_path = filedialog.askopenfilename(filetypes=[("Image files", "*.jpg;*.png;*.jpeg")])
if file_path:
global img, img_display
img = Image.open(file_path)
img_display = img.resize((250, 250))
img_tk = ImageTk.PhotoImage(img_display)
panel.config(image=img_tk)
panel.image = img_tk
def edit_and_save():
if img:
img_resized = img.resize((400, 400))
enhancer = ImageEnhance.Brightness(img_resized)
img_bright = enhancer.enhance(1.5)
save_path = filedialog.asksaveasfilename(defaultextension=".jpg", filetypes=[("JPEG", "*.jpg")])
if save_path:
img_bright.save(save_path)
messagebox.showinfo("Success", f"Image saved as {save_path}")
root = tk.Tk()
root.title("Simple Image Editor")
img = None
img_display = None
btn_open = tk.Button(root, text="Open Image", command=open_image)
btn_open.pack()
panel = tk.Label(root)
panel.pack()
btn_save = tk.Button(root, text="Edit & Save", command=edit_and_save)
btn_save.pack()
root.mainloop()