-
Notifications
You must be signed in to change notification settings - Fork 49
/
workping.py
31 lines (28 loc) · 1.17 KB
/
workping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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}`")