From 2faed653d75547ac40b955971b6ca481b82586d7 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Wed, 18 Oct 2023 20:10:17 +1100 Subject: [PATCH] fix(api): deduplicate metadata/workflow extraction logic --- invokeai/app/api/routers/images.py | 2 +- .../services/image_files/image_files_disk.py | 18 ++++-------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/invokeai/app/api/routers/images.py b/invokeai/app/api/routers/images.py index 429eaef37c..a57414e17f 100644 --- a/invokeai/app/api/routers/images.py +++ b/invokeai/app/api/routers/images.py @@ -60,10 +60,10 @@ async def upload_image( bbox = pil_image.getbbox() pil_image = pil_image.crop(bbox) except Exception: - # Error opening the image ApiDependencies.invoker.services.logger.error(traceback.format_exc()) raise HTTPException(status_code=415, detail="Failed to read image") + # TODO: retain non-invokeai metadata on upload? # attempt to parse metadata from image metadata_raw = pil_image.info.get("invokeai_metadata", None) if metadata_raw: diff --git a/invokeai/app/services/image_files/image_files_disk.py b/invokeai/app/services/image_files/image_files_disk.py index e8a733d619..91c1e14789 100644 --- a/invokeai/app/services/image_files/image_files_disk.py +++ b/invokeai/app/services/image_files/image_files_disk.py @@ -65,20 +65,10 @@ class DiskImageFileStorage(ImageFileStorageBase): pnginfo = PngImagePlugin.PngInfo() - if metadata is not None or workflow is not None: - if metadata is not None: - pnginfo.add_text("invokeai_metadata", metadata.model_dump_json()) - if workflow is not None: - pnginfo.add_text("invokeai_workflow", workflow.model_dump_json()) - else: - # For uploaded images, we want to retain metadata. PIL strips it on save; manually add it back - # TODO: retain non-invokeai metadata on save... - original_metadata = image.info.get("invokeai_metadata", None) - if original_metadata is not None: - pnginfo.add_text("invokeai_metadata", original_metadata) - original_workflow = image.info.get("invokeai_workflow", None) - if original_workflow is not None: - pnginfo.add_text("invokeai_workflow", original_workflow) + if metadata is not None: + pnginfo.add_text("invokeai_metadata", metadata.model_dump_json()) + if workflow is not None: + pnginfo.add_text("invokeai_workflow", workflow.model_dump_json()) image.save( image_path,