MCPcopy
hub / github.com/crystian/ComfyUI-Crystools / execute

Method execute

nodes/image.py:382–428  ·  view source on GitHub ↗
(self, image=None, filename_prefix="ComfyUI", with_workflow=True, metadata_extra=None, prompt=None, extra_pnginfo=None)

Source from the content-addressed store, hash-verified

380 FUNCTION = "execute"
381
382 def execute(self, image=None, filename_prefix="ComfyUI", with_workflow=True, metadata_extra=None, prompt=None, extra_pnginfo=None):
383 data = {
384 "result": [''],
385 "ui": {
386 "text": [''],
387 "images": [],
388 }
389 }
390 if image is not None:
391 if with_workflow is True:
392 extra_pnginfo_new = extra_pnginfo.copy()
393 prompt = prompt.copy()
394 else:
395 extra_pnginfo_new = None
396 prompt = None
397
398 if metadata_extra is not None and metadata_extra != 'undefined':
399 try:
400 # metadata_extra = json.loads(f"{{{metadata_extra}}}") // a fix?
401 metadata_extra = json.loads(metadata_extra)
402 except Exception as e:
403 logger.error(f"Error parsing metadata_extra (it will send as string), error: {e}")
404 metadata_extra = {"extra": str(metadata_extra)}
405
406 if isinstance(metadata_extra, dict):
407 for k, v in metadata_extra.items():
408 if extra_pnginfo_new is None:
409 extra_pnginfo_new = {}
410
411 extra_pnginfo_new[k] = v
412
413 saved = super().save_images(image, filename_prefix, prompt, extra_pnginfo_new)
414
415 image = saved["ui"]["images"][0]
416 image_path = Path(self.output_dir).joinpath(image["subfolder"], image["filename"])
417 img, promptFromImage, metadata = buildMetadata(image_path)
418
419 images = [image]
420 result = metadata
421
422 data["result"] = [result]
423 data["ui"]["images"] = images
424
425 else:
426 logger.debug("Source: Empty on CImageSaveWithExtraMetadata")
427
428 return data
429
430
431

Callers

nothing calls this directly

Calls 1

buildMetadataFunction · 0.85

Tested by

no test coverage detected