diff --git a/.gitignore b/.gitignore index 3d95742..f3acea0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ __pycache__/ .Python build/ develop-eggs/ -#dist/ +dist/ downloads/ eggs/ .eggs/ diff --git a/README.md b/README.md index 42bad86..d96524c 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ Useful for Civitai, sharing on Discord, or messing with people. ### How to use -Download the `.exe` file in the dist folder and enjoy. +Download the `.pyw` file and run it with Python. -Alternatively, download the `.pyw` file and run it with Python. +Alternatively, download the `.exe` from the [Releases](https://github.com/hollowstrawberry/png_info_editor/releases). -![preview](preview.png) +![preview](images/screenshot.png) diff --git a/dist/png_info_editor.exe b/dist/png_info_editor.exe deleted file mode 100644 index c9e27b7..0000000 Binary files a/dist/png_info_editor.exe and /dev/null differ diff --git a/dist/example.png b/images/example.png similarity index 100% rename from dist/example.png rename to images/example.png diff --git a/images/screenshot.png b/images/screenshot.png new file mode 100644 index 0000000..d4fd4d6 Binary files /dev/null and b/images/screenshot.png differ diff --git a/dist/test.png b/images/test.png similarity index 99% rename from dist/test.png rename to images/test.png index 204e36a..2fdaace 100644 Binary files a/dist/test.png and b/images/test.png differ diff --git a/dist/test_original.png b/images/test_original.png similarity index 100% rename from dist/test_original.png rename to images/test_original.png diff --git a/png_info_editor.pyw b/png_info_editor.pyw index 36ef5ab..840f8e5 100644 --- a/png_info_editor.pyw +++ b/png_info_editor.pyw @@ -4,42 +4,40 @@ import tkinter as tk from tkinter import filedialog, messagebox from PIL import Image, PngImagePlugin +START = "1.0" +ERROR = "Oops" + def select_source_file(): global source_label, textbox - filename = filedialog.askopenfilename(initialdir=os.getcwd(), - title="Select source file", - filetypes=(("PNG", "*.png"),)) + filename = filedialog.askopenfilename(initialdir=os.getcwd(), title="Select source file", filetypes=(("PNG", "*.png"),)) if filename: with Image.open(filename, formats=("png",)) as source: info = source.info.get("parameters", None) if not info: return messagebox.showerror(title="Oops", message="No PNG info found in this image.") source_label.config(text=f"{filename.split('/')[-1]}") - source_file = filename - textbox.delete("1.0", "end") - textbox.insert("1.0", info) + textbox.delete(START, tk.END) + textbox.insert(START, info) apply_color() def select_target_file(): global target_file, target_label - filename = filedialog.askopenfilename(initialdir=os.getcwd(), - title="Select target file", - filetypes=(("PNG", "*.png"),)) + filename = filedialog.askopenfilename( initialdir=os.getcwd(), title="Select target file", filetypes=(("PNG", "*.png"),)) if filename: target_label.config(text=f"{filename.split('/')[-1]}") target_file = filename def copy_png_info(): global target_file, textbox - info = textbox.get("1.0",'end-1c').strip() + info = textbox.get(START, tk.END).strip() if not info: - return messagebox.showerror(title="Oops", message="Please select a file to copy PNG info from, or write your own.") + return messagebox.showerror(title=ERROR, message="Please select a file to copy PNG info from, or write your own.") if not target_file: - return messagebox.showerror(title="Oops", message="Please select a target image to save the PNG info to.") + return messagebox.showerror(title=ERROR, message="Please select a target image to save the PNG info to.") try: target = Image.open(target_file, formats=("png",)) except: - return messagebox.showerror(title="Oops", message="The target image might've been moved or is invalid.") + return messagebox.showerror(title=ERROR, message="The target image might've been moved or is invalid.") pnginfo = PngImagePlugin.PngInfo() pnginfo.add_text("parameters", info) target.save(target_file, format="png", pnginfo=pnginfo) @@ -48,17 +46,13 @@ def copy_png_info(): def apply_color(event=None): global textbox, tags for tag in tags: - textbox.tag_remove(tag, "1.0", "end") - lines = textbox.get("1.0", "end").splitlines() + textbox.tag_remove(tag, START, tk.END) + lines = textbox.get(START, tk.END).splitlines() for i, line in enumerate(lines): for tag, pattern in tags.items(): for match in re.finditer(pattern, line): textbox.tag_add(tag, f"{i+1}.{match.start(1)}", f"{i+1}.{match.end(1)}") - -WIDTH = 700 -HEIGHT = 400 - tags = { "blue": r"(?:^|, )([\w ]+):", "purple": r"(<\w+:[^>]+>)", @@ -68,32 +62,30 @@ target_file = "" window = tk.Tk() window.title("PNG Info editor") -window.geometry(f"{WIDTH}x{HEIGHT}") -boxtop = tk.Frame(window, width=WIDTH, height=50) -boxmiddle = tk.Frame(window, width=WIDTH, height=100) -boxbottom = tk.Frame(window, width=WIDTH, height=250) -window.columnconfigure(0, minsize=WIDTH) -boxtop.grid(row=0, pady=10) +boxtop = tk.Frame(window) +boxmiddle = tk.Frame(window) +boxbottom = tk.Frame(window) +boxtop.grid(row=0) boxmiddle.grid(row=1) -boxbottom.grid(row=2) -boxmiddle.grid_propagate(0) -boxmiddle.columnconfigure(0, minsize=WIDTH//2-40) -boxmiddle.columnconfigure(2, minsize=WIDTH//2-40) +boxbottom.grid(row=2, padx=5, pady=(0, 10)) +for i in range(5): + boxmiddle.columnconfigure(i, minsize=100) tk.Label(boxtop, text="This program lets you copy and edit Stable Diffusion Generation data between images.").pack() -tk.Button(boxmiddle, text="Copy from image", command=select_source_file).grid(row=0, column=0) -tk.Button(boxmiddle, text="Select target image", command=select_target_file).grid(row=0, column=2) -tk.Button(boxmiddle, text="Copy to target", command=copy_png_info).grid(row=2, column=1) +tk.Button(boxmiddle, text="Copy from image", command=select_source_file).grid(row=0, column=1) +tk.Button(boxmiddle, text="Select target image", command=select_target_file).grid(row=0, column=3) source_label = tk.Label(boxmiddle, text="No file selected.") target_label = tk.Label(boxmiddle, text="No file selected.") -source_label.grid(row=1, column=0) -target_label.grid(row=1, column=2) -scrollbar = tk.Scrollbar(boxbottom, orient='vertical') -scrollbar.pack(side="right", fill='y') -textbox = tk.Text(boxbottom, width=80, height=15, font=("Lucida Sans Typewriter",10), yscrollcommand=scrollbar.set) +source_label.grid(row=1, column=1) +target_label.grid(row=1, column=3) + +tk.Button(boxbottom, text="Copy to target", command=copy_png_info).pack(side=tk.TOP, pady=5) +scrollbar = tk.Scrollbar(boxbottom, orient="vertical") +textbox = tk.Text(boxbottom, font=("Lucida Sans Typewriter", 10), yscrollcommand=scrollbar.set) scrollbar.config(command=textbox.yview) -textbox.pack() +scrollbar.pack(side=tk.RIGHT, fill=tk.Y) +textbox.pack(expand=True, fill=tk.BOTH) textbox.bind("", apply_color) for tag in tags: