feat(nodes): format option for get_image method

Also default CNet preprocessors to "RGB"
This commit is contained in:
dunkeroni 2024-02-18 15:42:58 -05:00 committed by Brandon Rising
parent ee2ef470a7
commit d17a0779cc
2 changed files with 10 additions and 3 deletions

View File

@ -144,7 +144,7 @@ class ImageProcessorInvocation(BaseInvocation, WithMetadata, WithBoard):
return image
def invoke(self, context: InvocationContext) -> ImageOutput:
raw_image = context.images.get_pil(self.image.image_name)
raw_image = context.images.get_pil(self.image.image_name, "RGB")
# image type should be PIL.PngImagePlugin.PngImageFile ?
processed_image = self.run_processor(raw_image)

View File

@ -194,13 +194,20 @@ class ImagesInterface(InvocationContextInterface):
node_id=self._context_data.invocation.id,
)
def get_pil(self, image_name: str) -> Image:
def get_pil(self, image_name: str, format: str | None = None) -> Image:
"""
Gets an image as a PIL Image object.
:param image_name: The name of the image to get.
:param format: The color format to convert the image to. If None, the original format is used.
"""
return self._services.images.get_pil_image(image_name)
image = self._services.images.get_pil_image(image_name)
if format and format != image.mode:
try:
image = image.convert(format)
except ValueError:
self._services.logger.warning(f"Could not convert image from {image.mode} to {format}. Using original format.")
return image
def get_metadata(self, image_name: str) -> Optional[MetadataField]:
"""