mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -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}")
|
||||
img.save(file_path, format="JPEG", **save_kwargs)
|
||||
elif file_format == "webp":
|
||||
# For WebP, also use piexif for metadata
|
||||
if metadata:
|
||||
try:
|
||||
exif_dict = {'Exif': {piexif.ExifIFD.UserComment: b'UNICODE\0' + metadata.encode('utf-16be')}}
|
||||
exif_bytes = piexif.dump(exif_dict)
|
||||
save_kwargs["exif"] = exif_bytes
|
||||
except Exception as e:
|
||||
print(f"Error adding EXIF data: {e}")
|
||||
# For WebP, use exif data in a ComfyUI-compatible format
|
||||
try:
|
||||
# Get exif from image
|
||||
exif = img.getexif()
|
||||
|
||||
# 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:
|
||||
print(f"Error adding EXIF/workflow data to WebP: {e}")
|
||||
|
||||
img.save(file_path, format="WEBP", **save_kwargs)
|
||||
|
||||
results.append({
|
||||
|
||||
Reference in New Issue
Block a user