mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
[Feature] Command-line script for viewing PNG metadata (#4587)
## What type of PR is this? (check all applicable) - [X] Feature ## Have you discussed this change with the InvokeAI team? - [X] No, because it is trivial ## Have you updated all relevant documentation? - [X] Yes -- added a new page listing all the command-line scripts and their most useful options. ## Description InvokeAI version 2.3 had a script called `invokeai-metadata` that accepted a list of png images and printed out JSON-formatted embedded metadata. I used to use the script for sorting and tagging images outside of the InvokeAI Web UI framework, and I think people might still find it useful. This script stopped working in 3.0 and I didn't notice that until just now. This PR restores it to a functional state. ## Related Tickets & Documents None
This commit is contained in:
commit
41dad2013a
@ -51,6 +51,9 @@ Prevent InvokeAI from displaying unwanted racy images.
|
|||||||
### * [Controlling Logging](LOGGING.md)
|
### * [Controlling Logging](LOGGING.md)
|
||||||
Control how InvokeAI logs status messages.
|
Control how InvokeAI logs status messages.
|
||||||
|
|
||||||
|
### * [Command-line Utilities](UTILITIES.md)
|
||||||
|
A list of the command-line utilities available with InvokeAI.
|
||||||
|
|
||||||
<!-- OUT OF DATE
|
<!-- OUT OF DATE
|
||||||
### * [Miscellaneous](OTHER.md)
|
### * [Miscellaneous](OTHER.md)
|
||||||
Run InvokeAI on Google Colab, generate images with repeating patterns,
|
Run InvokeAI on Google Colab, generate images with repeating patterns,
|
||||||
|
@ -147,6 +147,7 @@ Mac and Linux machines, and runs on GPU cards with as little as 4 GB of RAM.
|
|||||||
|
|
||||||
### InvokeAI Configuration
|
### InvokeAI Configuration
|
||||||
- [Guide to InvokeAI Runtime Settings](features/CONFIGURATION.md)
|
- [Guide to InvokeAI Runtime Settings](features/CONFIGURATION.md)
|
||||||
|
- [Database Maintenance and other Command Line Utilities](features/UTILITIES.md)
|
||||||
|
|
||||||
## :octicons-log-16: Important Changes Since Version 2.3
|
## :octicons-log-16: Important Changes Since Version 2.3
|
||||||
|
|
||||||
|
46
invokeai/backend/image_util/invoke_metadata.py
Normal file
46
invokeai/backend/image_util/invoke_metadata.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# Copyright (c) 2023 Lincoln D. Stein and the InvokeAI Development Team
|
||||||
|
|
||||||
|
"""Very simple functions to fetch and print metadata from InvokeAI-generated images."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any, Dict
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
|
def get_invokeai_metadata(image_path: Path) -> Dict[str, Any]:
|
||||||
|
"""
|
||||||
|
Retrieve "invokeai_metadata" field from png image.
|
||||||
|
|
||||||
|
:param image_path: Path to the image to read metadata from.
|
||||||
|
May raise:
|
||||||
|
OSError -- image path not found
|
||||||
|
KeyError -- image doesn't contain the metadata field
|
||||||
|
"""
|
||||||
|
image: Image = Image.open(image_path)
|
||||||
|
return json.loads(image.text["invokeai_metadata"])
|
||||||
|
|
||||||
|
|
||||||
|
def print_invokeai_metadata(image_path: Path):
|
||||||
|
"""Pretty-print the metadata."""
|
||||||
|
try:
|
||||||
|
metadata = get_invokeai_metadata(image_path)
|
||||||
|
print(f"{image_path}:\n{json.dumps(metadata, sort_keys=True, indent=4)}")
|
||||||
|
except OSError:
|
||||||
|
print(f"{image_path}:\nNo file found.")
|
||||||
|
except KeyError:
|
||||||
|
print(f"{image_path}:\nNo metadata found.")
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Run the command-line utility."""
|
||||||
|
image_paths = sys.argv[1:]
|
||||||
|
if not image_paths:
|
||||||
|
print(f"Usage: {Path(sys.argv[0]).name} image1 image2 image3 ...")
|
||||||
|
print("\nPretty-print InvokeAI image metadata from the listed png files.")
|
||||||
|
sys.exit(-1)
|
||||||
|
for img in image_paths:
|
||||||
|
print_invokeai_metadata(img)
|
@ -142,7 +142,7 @@ dependencies = [
|
|||||||
"invokeai-model-install" = "invokeai.frontend.install.model_install:main"
|
"invokeai-model-install" = "invokeai.frontend.install.model_install:main"
|
||||||
"invokeai-migrate3" = "invokeai.backend.install.migrate_to_3:main"
|
"invokeai-migrate3" = "invokeai.backend.install.migrate_to_3:main"
|
||||||
"invokeai-update" = "invokeai.frontend.install.invokeai_update:main"
|
"invokeai-update" = "invokeai.frontend.install.invokeai_update:main"
|
||||||
"invokeai-metadata" = "invokeai.frontend.CLI.sd_metadata:print_metadata"
|
"invokeai-metadata" = "invokeai.backend.image_util.invoke_metadata:main"
|
||||||
"invokeai-node-cli" = "invokeai.app.cli_app:invoke_cli"
|
"invokeai-node-cli" = "invokeai.app.cli_app:invoke_cli"
|
||||||
"invokeai-node-web" = "invokeai.app.api_app:invoke_api"
|
"invokeai-node-web" = "invokeai.app.api_app:invoke_api"
|
||||||
"invokeai-import-images" = "invokeai.frontend.install.import_images:main"
|
"invokeai-import-images" = "invokeai.frontend.install.import_images:main"
|
||||||
|
Loading…
Reference in New Issue
Block a user