4k / README.md
Pq234's picture
Update README.md
72e5377 verified
|
Raw
History Blame Contribute Delete
2.95 kB
metadata
title: 4k
emoji: 🖼️
colorFrom: yellow
colorTo: red
sdk: static
pinned: false
license: bsd-3-clause-clear
short_description: import gradio as gr from PIL import Image, ImageEnhance, Ima

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference 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.

Here’s a minimal but functional example:

`python import tkinter as tk from tkinter import filedialog from PIL import Image, ImageTk, ImageOps

class PhotoEditor: def init(self, root): self.root = root self.root.title("Simple Photo Editor")

    self.image = None
    self.tk_image = None

    # Buttons
    tk.Button(root, text="Open Image", command=self.open_image).pack()
    tk.Button(root, text="Rotate 90°", command=self.rotate_image).pack()
    tk.Button(root, text="Grayscale", command=self.grayscale_image).pack()
    tk.Button(root, text="Resize Half", command=self.resize_image).pack()
    tk.Button(root, text="Save Image", command=self.save_image).pack()

    # Canvas
    self.canvas = tk.Label(root)
    self.canvas.pack()

def open_image(self):
    file_path = filedialog.askopenfilename()
    if file_path:
        self.image = Image.open(file_path)
        self.display_image()

def display_image(self):
    self.tk_image = ImageTk.PhotoImage(self.image)
    self.canvas.config(image=self.tk_image)

def rotate_image(self):
    if self.image:
        self.image = self.image.rotate(90, expand=True)
        self.display_image()

def grayscale_image(self):
    if self.image:
        self.image = ImageOps.grayscale(self.image)
        self.display_image()

def resize_image(self):
    if self.image:
        w, h = self.image.size
        self.image = self.image.resize((w // 2, h // 2))
        self.display_image()

def save_image(self):
    if self.image:
        file_path = filedialog.asksaveasfilename(defaultextension=".png")
        if file_path:
            self.image.save(file_path)

if name == "main": root = tk.Tk() app = PhotoEditor(root) root.mainloop() `

🛠 How to run it

  1. Install dependencies: bash pip install pillow
  2. Save the code as photo_editor.py.
  3. Run: bash python photo_editor.py
  4. Use the buttons to open, edit, and save images.

✨ This is a starter app — you can expand it with features like brightness/contrast adjustment, filters, or drawing tools.

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?