mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-26 07:35:44 -03:00
Enhance WebP image saving: add EXIF data and workflow metadata support. Fixes #193
This commit is contained in:
@@ -379,14 +379,28 @@ class SaveImage:
|
|||||||
print(f"Error adding EXIF data: {e}")
|
print(f"Error adding EXIF data: {e}")
|
||||||
img.save(file_path, format="JPEG", **save_kwargs)
|
img.save(file_path, format="JPEG", **save_kwargs)
|
||||||
elif file_format == "webp":
|
elif file_format == "webp":
|
||||||
# For WebP, also use piexif for metadata
|
# For WebP, use exif data in a ComfyUI-compatible format
|
||||||
if metadata:
|
|
||||||
try:
|
try:
|
||||||
exif_dict = {'Exif': {piexif.ExifIFD.UserComment: b'UNICODE\0' + metadata.encode('utf-16be')}}
|
# Get exif from image
|
||||||
exif_bytes = piexif.dump(exif_dict)
|
exif = img.getexif()
|
||||||
save_kwargs["exif"] = exif_bytes
|
|
||||||
|
# Add metadata if available
|
||||||
|
if metadata:
|
||||||
|
exif[piexif.ExifIFD.UserComment] = b'UNICODE\0' + metadata.encode('utf-16be')
|
||||||
|
|
||||||
|
# Add workflow if embed_workflow is enabled
|
||||||
|
if embed_workflow and extra_pnginfo is not None:
|
||||||
|
# Format the workflow with "Workflow:" prefix for ComfyUI compatibility
|
||||||
|
workflow_json = json.dumps(extra_pnginfo["workflow"])
|
||||||
|
# Store workflow in ImageDescription tag (0x010e)
|
||||||
|
exif[piexif.ImageIFD.ImageDescription] = "Workflow:" + workflow_json
|
||||||
|
|
||||||
|
# Update save_kwargs with exif data
|
||||||
|
save_kwargs["exif"] = exif.tobytes()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error adding EXIF data: {e}")
|
print(f"Error adding EXIF/workflow data to WebP: {e}")
|
||||||
|
|
||||||
img.save(file_path, format="WEBP", **save_kwargs)
|
img.save(file_path, format="WEBP", **save_kwargs)
|
||||||
|
|
||||||
results.append({
|
results.append({
|
||||||
|
|||||||
Reference in New Issue
Block a user