From ddc4ff249f64bff2bc80c9b4c6a7b46ae87ef49c Mon Sep 17 00:00:00 2001 From: wyrde Date: Wed, 5 Apr 2023 14:42:08 -0400 Subject: [PATCH] misc files added more stutff, huzzah! --- misc/.ExifTool_config | 30 ++++++++++++++++++++++++++++++ misc/README.md | 16 ++++++++++++++++ misc/workping.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 misc/.ExifTool_config create mode 100644 misc/README.md create mode 100644 misc/workping.py diff --git a/misc/.ExifTool_config b/misc/.ExifTool_config new file mode 100644 index 0000000..81c0382 --- /dev/null +++ b/misc/.ExifTool_config @@ -0,0 +1,30 @@ +%Image::ExifTool::UserDefined = ( + # All EXIF tags are added to the Main table, and WriteGroup is used to + # specify where the tag is written (default is ExifIFD if not specified): + 'Image::ExifTool::Exif::Main' => { + # Example 1. EXIF:NewEXIFTag + 0xd000 => { + Name => 'NewEXIFTag', + Writable => 'int16u', + WriteGroup => 'IFD0', + }, + # add more user-defined EXIF tags here... + }, + # new PNG tags are added to the PNG::TextualData table: + 'Image::ExifTool::PNG::TextualData' => { +### wyrde 2023-04-03 +# # wyrde add 1. PNG:Prompt + Prompt => { }, +# # wyrde add 2, PNG:Workflow + Workflow => { }, +# # wyrde add 3. PNG:Parameters + Parameters => { }, +# # wyrde add 4, PNG:SDpos + SDpos => { }, +# # wyrde add 5. PNG:SDneg + SDneg => { }, +# # wyrde add 6. PNG:SDconf + SDconf => { }, + }, + +); diff --git a/misc/README.md b/misc/README.md new file mode 100644 index 0000000..97245a1 --- /dev/null +++ b/misc/README.md @@ -0,0 +1,16 @@ +# misc files that don't fit elsewhere + + +## .Exiftool_config +a configuration file that adds some SD-related tags allowing exiftool to edit them. It can read the tags but cannot edit them until they are defined. +### related: +* https://exiftool.org/ +* https://github.com/hvdwolf/jExifToolGUI/releases + +## workping.py +A CLI script for adding a workflow to a PNG file. Requres Pillow module (PIL). It updates the image file, make a backup if you want extra safety. +python workping.py --image "/path/to/image.png" --workflow "/path/to/workflow.json" +### related +* source: https://colab.research.google.com/drive/1hQMjNUdhMQ3rw1Wcm3_umvmOMeS_K4s8?usp=sharing#scrollTo=llbal5zlANoH +* PIL: https://pillow.readthedocs.io/en/stable/installation.html + diff --git a/misc/workping.py b/misc/workping.py new file mode 100644 index 0000000..1231171 --- /dev/null +++ b/misc/workping.py @@ -0,0 +1,31 @@ +import argparse +import os +from PIL import Image, PngImagePlugin + +def make_workflow_png(image, workflow): + if not os.path.exists(image): + ValueError(f"Invalid image path `{image}`") + if not os.path.exists(workflow): + ValueError(f"Invalid workflow path `{workflow}`") + path = os.path.dirname(image) + filename = os.path.basename(image).rsplit('.', 1)[0] + try: + with open(workflow, "r") as file: + data = file.read() + except OSError as e: + Exception("There was an error reading the workflow JSON:", e) + image = Image.open(image) + info = PngImagePlugin.PngInfo() + info.add_text("workflow", data) + new_path = os.path.join(path, filename+'.png') + image.save(new_path, "PNG", pnginfo=info) + return new_path + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Add workflow metadata to a PNG image") + parser.add_argument("--image", type=str, help="Path to the PNG image") + parser.add_argument("--workflow", type=str, help="Path to the workflow JSON file") + args = parser.parse_args() + new_image_path = make_workflow_png(args.image, args.workflow) + + print(f"Workflow added to `{new_image_path}`")