diff --git a/nodes/image_saver.py b/nodes/image_saver.py index 3e24deb..a51c79d 100644 --- a/nodes/image_saver.py +++ b/nodes/image_saver.py @@ -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", -} \ No newline at end of file +} diff --git a/pyproject.toml b/pyproject.toml index 98e7d38..969ccc2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" \ No newline at end of file