Files
ComfyAssets-ComfyUI_PromptM…/tools/make_avif_fixture.py
T
1439a5ef19 feat(images): collect AVIF as a media type (#652) (#673)
* Fix DB threading, recent ordering, restore size, and scan timestamps

* Fix subfolders API missing include_ancestors param

* refactor: move api code into promptmanager_core package

* chore: ignore local config, tracking state, and db backups

* Fix: fall back to original source when thumbnail img fails to load

* fix(core): apply code review fixes, optimizations, and schema compliance

- Fix KeyError in image_monitor _get_fallback_prompt dictionary handling
- Add secondary LoRA hash stripping in image_monitor prompt lookup
- Protect dual PromptManager workflows from metadata overwrite in patched_save_images
- Support WebP, JPEG, and GIF metadata extraction via image.info
- Add default values for prepend_text and append_text in INPUT_TYPES
- Add **kwargs to encode_prompt, process_text, search, and IS_CHANGED
- Declare explicit RETURN_NAMES across PromptManager and PromptManagerText
- Add close() proxy to PromptDatabase and fix Windows SQLite connection locks
- Normalize database and subfolder paths for cross-platform consistency
- Update test suite teardown handlers and mock targets across 17 test modules
- Add comprehensive CHANGELOG.md and issue.txt tracking documentation

* Close test databases before unlinking temp files

The usage and image-linking tests unlinked their temp database while the
persistent SQLite connection was still open, so Windows raised WinError 32
from tearDown (POSIX allows unlinking an open file, so upstream CI never
saw it). Close the database first and ignore a transient lock, matching
tests/test_database.py.

* Ignore local tracking state and prebackfill database backup

* style: restore black formatting after 3.6.0 merge

The fork-only default:" additions to prepend_text/append_text dropped the
trailing commas, which black reformats. This is the entire cause of Tests #4
on main: black --check failed with 'would reformat prompt_manager.py'
while every other job (test matrix, coverage, comfyui, js-test) passed.

No behaviour change.

* feat(images): collect AVIF as a media type (#652)

The EXIF reader from #650 reads the prompt and workflow records ComfyUI's
SaveImageAdvanced writes into an AVIF, but no file-type list named .avif, so
neither the scan nor the monitor ever handed it one.

Every list now names .avif: the scan and its deletion allowlist, the monitor's
default and fallback, the gallery and thumbnail walks, serving and Inspect,
auto-tagging's listing and its path check, the capture store, the preview
source order and the diagnostics count.

Pillow's floor here is >= 10.1.0 (ComfyUI's) and Pillow opens AVIF only from
11.0, and only when built with an AVIF decoder. utils/media_formats.collectable
asks PIL.features.check("avif") at every collection point, so a Pillow without
AVIF skips the file quietly and behaves exactly as before #652; the tests pin
both answers on the gallery walk, the monitor, auto-tagging, the capture store
and the scan.

gallery.monitoring.extensions is saved per install and overrides the default,
so a list saved before #652 gains .avif last on load, keeping every entry the
install chose; an empty list stays empty, and a value that is not a list keeps
the current one.

The fixture is tests/fixtures/media/comfyui_avif.avif: a 1 KB still written by
ComfyUI's own _save_avif (tools/make_avif_fixture.py regenerates it) carrying a
PromptManager graph. The scan stores and links its prompt and pair; the monitor
links the same positive prompt from the file's own EXIF.

The local browser-only Inspect reader is unchanged: the bundled front-end
reader does not parse AVIF, so the chooser still offers what it can read.
Library Inspect reads an AVIF through the server, where Pillow answers.

* chore: drop two local ignore rules that are not part of AVIF support (#652)

---------

Co-authored-by: LacklusterOpsec <LacklusterOpsec@users.noreply.github.com>
Co-authored-by: Vito Sansevero <vito.sansevero@gmail.com>
2026-11-21 17:25:59 -08:00

83 lines
2.7 KiB
Python

"""Write tests/fixtures/media/comfyui_avif.avif with ComfyUI's own AVIF writer.
Run from a ComfyUI checkout with ComfyUI's Python (torch, and PyAV built with
SVT-AV1), because the fixture must be what ``SaveImageAdvanced`` writes, not
an AVIF some other encoder made:
cd /path/to/ComfyUI
python custom_nodes/ComfyUI-PromptManager/tools/make_avif_fixture.py
``comfy_extras.nodes_images._save_avif`` encodes the pixels through PyAV and
then ``inject_avif_metadata`` writes the same EXIF item ComfyUI writes:
``prompt:{json}`` at tag 0x0110, then ``workflow:{json}`` and every other key
from 0x010F down. ``utils/exif_text`` reads those tags back (#652).
The image is a 96x96 sRGB gradient at CRF 18: small enough to keep in the
repository and large enough that the EXIF item dominates the file.
"""
import json
import os
import sys
# Importing comfy_extras requires ComfyUI's own root on sys.path; the script
# is run from that root (see the docstring).
sys.path.insert(0, os.getcwd())
import torch # noqa: E402
from comfy_extras.nodes_images import _save_avif # noqa: E402
# A PromptManager run: the positive prompt is the node's own text (the shape
# tests/test_image_linking.py's graph uses), so both the scan and the monitor
# link the image to that stored prompt instead of calling it a foreign output.
PROMPT = {
"1": {
"class_type": "PromptManager",
"inputs": {"text": "a small avif fixture"},
},
"2": {"class_type": "CLIPTextEncode", "inputs": {"text": "bad"}},
"3": {
"class_type": "KSampler",
"inputs": {"positive": ["1", 0], "negative": ["2", 0]},
},
}
WORKFLOW = {
"nodes": [
{"id": 1, "type": "PromptManager", "inputs": {"text": "a small avif fixture"}},
{"id": 2, "type": "CLIPTextEncode", "inputs": {"text": "bad"}},
{"id": 3, "type": "KSampler", "inputs": {}},
],
"links": [
[1, 0, 3, 0, "CONDITIONING"],
[2, 0, 3, 1, "CONDITIONING"],
],
}
OUTPUT = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
"tests",
"fixtures",
"media",
"comfyui_avif.avif",
)
def main():
os.makedirs(os.path.dirname(OUTPUT), exist_ok=True)
# (frames, height, width, channels), floats in 0..1 as ComfyUI's IMAGE is.
ramp = torch.linspace(0.0, 1.0, 96).view(1, 1, 96, 1).expand(1, 96, 96, 3)
_save_avif(
ramp.contiguous(),
OUTPUT,
"8-bit YUV420",
"sRGB",
18,
metadata={"prompt": PROMPT, "workflow": WORKFLOW},
)
print(f"{OUTPUT}: {os.path.getsize(OUTPUT)} bytes")
print(json.dumps({"prompt_keys": list(PROMPT), "workflow_keys": list(WORKFLOW)}))
if __name__ == "__main__":
main()