mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(nodes): format option for get_image method
Also default CNet preprocessors to "RGB"
This commit is contained in:
parent
ee2ef470a7
commit
d17a0779cc
@ -144,7 +144,7 @@ class ImageProcessorInvocation(BaseInvocation, WithMetadata, WithBoard):
|
|||||||
return image
|
return image
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> ImageOutput:
|
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 ?
|
# image type should be PIL.PngImagePlugin.PngImageFile ?
|
||||||
processed_image = self.run_processor(raw_image)
|
processed_image = self.run_processor(raw_image)
|
||||||
|
|
||||||
|
@ -194,13 +194,20 @@ class ImagesInterface(InvocationContextInterface):
|
|||||||
node_id=self._context_data.invocation.id,
|
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.
|
Gets an image as a PIL Image object.
|
||||||
|
|
||||||
:param image_name: The name of the image to get.
|
: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]:
|
def get_metadata(self, image_name: str) -> Optional[MetadataField]:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user