Pq234 commited on
Commit
72e5377
·
verified ·
1 Parent(s): 728818a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +83 -0
README.md CHANGED
@@ -10,3 +10,86 @@ short_description: import gradio as gr from PIL import Image, ImageEnhance, Ima
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
13
+ Got it — you’d like runnable code for a photo editing app. Let’s make a simple starter project in Python using Tkinter for the interface and Pillow (PIL) for image editing. This will let you open an image, apply basic edits (rotate, grayscale, resize), and save the result.
14
+
15
+ Here’s a minimal but functional example:
16
+
17
+ `python
18
+ import tkinter as tk
19
+ from tkinter import filedialog
20
+ from PIL import Image, ImageTk, ImageOps
21
+
22
+ class PhotoEditor:
23
+ def init(self, root):
24
+ self.root = root
25
+ self.root.title("Simple Photo Editor")
26
+
27
+ self.image = None
28
+ self.tk_image = None
29
+
30
+ # Buttons
31
+ tk.Button(root, text="Open Image", command=self.open_image).pack()
32
+ tk.Button(root, text="Rotate 90°", command=self.rotate_image).pack()
33
+ tk.Button(root, text="Grayscale", command=self.grayscale_image).pack()
34
+ tk.Button(root, text="Resize Half", command=self.resize_image).pack()
35
+ tk.Button(root, text="Save Image", command=self.save_image).pack()
36
+
37
+ # Canvas
38
+ self.canvas = tk.Label(root)
39
+ self.canvas.pack()
40
+
41
+ def open_image(self):
42
+ file_path = filedialog.askopenfilename()
43
+ if file_path:
44
+ self.image = Image.open(file_path)
45
+ self.display_image()
46
+
47
+ def display_image(self):
48
+ self.tk_image = ImageTk.PhotoImage(self.image)
49
+ self.canvas.config(image=self.tk_image)
50
+
51
+ def rotate_image(self):
52
+ if self.image:
53
+ self.image = self.image.rotate(90, expand=True)
54
+ self.display_image()
55
+
56
+ def grayscale_image(self):
57
+ if self.image:
58
+ self.image = ImageOps.grayscale(self.image)
59
+ self.display_image()
60
+
61
+ def resize_image(self):
62
+ if self.image:
63
+ w, h = self.image.size
64
+ self.image = self.image.resize((w // 2, h // 2))
65
+ self.display_image()
66
+
67
+ def save_image(self):
68
+ if self.image:
69
+ file_path = filedialog.asksaveasfilename(defaultextension=".png")
70
+ if file_path:
71
+ self.image.save(file_path)
72
+
73
+ if name == "main":
74
+ root = tk.Tk()
75
+ app = PhotoEditor(root)
76
+ root.mainloop()
77
+ `
78
+
79
+ 🛠 How to run it
80
+ 1. Install dependencies:
81
+ `bash
82
+ pip install pillow
83
+ `
84
+ 2. Save the code as photo_editor.py.
85
+ 3. Run:
86
+ `bash
87
+ python photo_editor.py
88
+ `
89
+ 4. Use the buttons to open, edit, and save images.
90
+
91
+ ---
92
+
93
+ ✨ This is a starter app — you can expand it with features like brightness/contrast adjustment, filters, or drawing tools.
94
+
95
+ 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?