wyrde
2 years ago
3 changed files with 77 additions and 0 deletions
@ -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 => { }, |
||||
}, |
||||
|
||||
); |
@ -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 |
||||
|
@ -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}`") |
Loading…
Reference in new issue