Files changed (1) hide show
  1. 4k +81 -0
4k ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ `python
4
+ import tkinter as tk
5
+ from tkinter import filedialog
6
+ from PIL import Image, ImageTk, ImageOps
7
+
8
+ class PhotoEditor:
9
+ def init(self, root):
10
+ self.root = root
11
+ self.root.title("Simple Photo Editor")
12
+
13
+ self.image = None
14
+ self.tk_image = None
15
+
16
+ # Buttons
17
+ tk.Button(root, text="Open Image", command=self.open_image).pack()
18
+ tk.Button(root, text="Rotate 90°", command=self.rotate_image).pack()
19
+ tk.Button(root, text="Grayscale", command=self.grayscale_image).pack()
20
+ tk.Button(root, text="Resize Half", command=self.resize_image).pack()
21
+ tk.Button(root, text="Save Image", command=self.save_image).pack()
22
+
23
+ # Canvas
24
+ self.canvas = tk.Label(root)
25
+ self.canvas.pack()
26
+
27
+ def open_image(self):
28
+ file_path = filedialog.askopenfilename()
29
+ if file_path:
30
+ self.image = Image.open(file_path)
31
+ self.display_image()
32
+
33
+ def display_image(self):
34
+ self.tk_image = ImageTk.PhotoImage(self.image)
35
+ self.canvas.config(image=self.tk_image)
36
+
37
+ def rotate_image(self):
38
+ if self.image:
39
+ self.image = self.image.rotate(90, expand=True)
40
+ self.display_image()
41
+
42
+ def grayscale_image(self):
43
+ if self.image:
44
+ self.image = ImageOps.grayscale(self.image)
45
+ self.display_image()
46
+
47
+ def resize_image(self):
48
+ if self.image:
49
+ w, h = self.image.size
50
+ self.image = self.image.resize((w // 2, h // 2))
51
+ self.display_image()
52
+
53
+ def save_image(self):
54
+ if self.image:
55
+ file_path = filedialog.asksaveasfilename(defaultextension=".png")
56
+ if file_path:
57
+ self.image.save(file_path)
58
+
59
+ if name == "main":
60
+ root = tk.Tk()
61
+ app = PhotoEditor(root)
62
+ root.mainloop()
63
+ `
64
+
65
+ 🛠 How to run it
66
+ 1. Install dependencies:
67
+ `bash
68
+ pip install pillow
69
+ `
70
+ 2. Save the code as photo_editor.py.
71
+ 3. Run:
72
+ `bash
73
+ python photo_editor.py
74
+ `
75
+ 4. Use the buttons to open, edit, and save images.
76
+
77
+ ---
78
+
79
+ ✨ This is a starter app — you can expand it with features like brightness/contrast adjustment, filters, or drawing tools.
80
+
81
+ Would you like me to extend this into a more advanced editor (with sliders for brightness/contrast and undo/redo), or keep it lightweight and simple?