Bugfix: Image Saver won't save the image without EXIF_UserComment input

This commit is contained in:
alessandroperilli
2025-09-16 15:48:47 +01:00
parent 6b253cce06
commit 432e1991c0
2 changed files with 23 additions and 29 deletions
+21 -27
View File
@@ -179,8 +179,23 @@ class OCS_ImageSaver:
):
try:
exif_bytes = None
exif_dict = {}
if EXIF_UserComment:
try:
# Store user comment with UTF-16BE encoding per EXIF spec
exif_payload = {
"Exif": {
piexif.ExifIFD.UserComment: b"UNICODE\0" + EXIF_UserComment.encode("utf-16be")
}
}
exif_bytes = piexif.dump(exif_payload)
except Exception as e:
print(f"Error adding EXIF data: {e}")
save_kwargs = {}
if exif_bytes is not None:
save_kwargs["exif"] = exif_bytes
if image_format == "png":
pnginfo = PngImagePlugin.PngInfo()
@@ -189,37 +204,16 @@ class OCS_ImageSaver:
workflow_json = json.dumps(extra_pnginfo["workflow"])
pnginfo.add_text("workflow", workflow_json)
if EXIF_UserComment:
exif_dict['Exif'] = {piexif.ExifIFD.UserComment: b'UNICODE\0' + EXIF_UserComment.encode('utf-16be')}
exif_bytes = piexif.dump(exif_dict)
img.save(path, pnginfo=pnginfo, exif=exif_bytes)
img.save(path, pnginfo=pnginfo, **save_kwargs)
elif image_format == "webp":
try:
if EXIF_UserComment:
exif_dict['Exif'] = {piexif.ExifIFD.UserComment: b'UNICODE\0' + EXIF_UserComment.encode('utf-16be')}
exif_bytes = piexif.dump(exif_dict)
except Exception as e:
print(f"Error adding EXIF data: {e}")
img.save(path, "WEBP", lossless=lossless_webp, quality=quality, exif=exif_bytes)
img.save(path, "WEBP", lossless=lossless_webp, quality=quality, **save_kwargs)
elif image_format in {"jpg", "jpeg"}:
if EXIF_UserComment:
try:
exif_dict['Exif'] = {piexif.ExifIFD.UserComment: b'UNICODE\0' + EXIF_UserComment.encode('utf-16be')}
exif_bytes = piexif.dump(exif_dict)
img.convert("RGB").save(path, quality=quality, **save_kwargs)
except Exception as e:
print(f"Error adding EXIF data: {e}")
img.convert("RGB").save(path, quality=quality, exif=exif_bytes)
except Exception as e:
print(f"Error saving image: {e}")
print(f"Error saving image: {e}")
NODE_CLASS_MAPPINGS = {
@@ -228,4 +222,4 @@ NODE_CLASS_MAPPINGS = {
NODE_DISPLAY_NAME_MAPPINGS = {
"OCS_ImageSaver": "Image Saver",
}
}
+2 -2
View File
@@ -1,7 +1,7 @@
[project]
name = "OCS_Nodes"
description = "A custom node suite to augment the capabilities of the [a/Open Creative Studio for ComfyUI](https://oc.studio/)."
version = "1.1.1"
version = "1.1.2"
license = {file = "LICENSE"}
[project.urls]
@@ -11,4 +11,4 @@ Repository = "https://github.com/alessandroperilli/OCS_Nodes"
[tool.comfy]
PublisherId = "perilli"
DisplayName = "Open Creative Studio Nodes"
Icon = "https://download.oc.studio/OCS_Nodes_Logo.png"
Icon = "https://assets.oc.studio/logos/ocs-nodes-logo.webp"