|
3 | 3 | from griptape.artifacts import ImageUrlArtifact |
4 | 4 | from griptape_nodes.exe_types.core_types import NodeMessageResult, Parameter, ParameterMode |
5 | 5 | from griptape_nodes.exe_types.node_types import BaseNode, SuccessFailureNode |
| 6 | +from griptape_nodes.exe_types.param_components.project_file_parameter import ProjectFileParameter |
6 | 7 | from griptape_nodes.retained_mode.griptape_nodes import logger |
7 | 8 | from griptape_nodes.traits.button import Button, ButtonDetailsMessagePayload |
8 | 9 | from griptape_nodes.traits.options import Options |
|
12 | 13 | ArtifactTetheringConfig, |
13 | 14 | default_extract_url_from_artifact_value, |
14 | 15 | ) |
15 | | -from griptape_nodes_library.utils.file_utils import generate_filename |
16 | 16 | from griptape_nodes_library.utils.image_utils import ( |
17 | 17 | SUPPORTED_IMAGE_EXTENSIONS, |
18 | 18 | dict_to_image_url_artifact, |
19 | 19 | extract_channel_from_image, |
| 20 | + image_to_bytes, |
20 | 21 | load_pil_from_url, |
21 | | - save_pil_image_with_named_filename, |
22 | 22 | ) |
23 | 23 | from griptape_nodes_library.utils.macro_path_utils import ( |
24 | 24 | copy_external_file_to_project, |
@@ -96,6 +96,13 @@ def __init__(self, **kwargs) -> None: |
96 | 96 | ) |
97 | 97 | self.add_parameter(channel_param) |
98 | 98 |
|
| 99 | + self._mask_output_file = ProjectFileParameter( |
| 100 | + node=self, |
| 101 | + name="mask_output_file", |
| 102 | + default_filename="mask.png", |
| 103 | + ) |
| 104 | + self._mask_output_file.add_parameter() |
| 105 | + |
99 | 106 | self.add_parameter( |
100 | 107 | Parameter( |
101 | 108 | name="output_mask", |
@@ -318,13 +325,11 @@ def _extract_channel_as_mask(self, image_artifact: ImageUrlArtifact, channel: st |
318 | 325 | # Extract the specified channel as mask |
319 | 326 | mask = extract_channel_from_image(image_pil, channel, "image") |
320 | 327 |
|
321 | | - # Save output mask and create URL artifact with proper filename |
322 | | - filename = generate_filename( |
323 | | - node_name=self.name, |
324 | | - suffix="_load_mask", |
325 | | - extension="png", |
326 | | - ) |
327 | | - output_artifact = save_pil_image_with_named_filename(mask, filename, "PNG") |
| 328 | + # Save output mask and create URL artifact |
| 329 | + image_bytes = image_to_bytes(mask, "PNG") |
| 330 | + dest = self._mask_output_file.build_file() |
| 331 | + saved = dest.write_bytes(image_bytes) |
| 332 | + output_artifact = ImageUrlArtifact(saved.location) |
328 | 333 | self.set_parameter_value("output_mask", output_artifact) |
329 | 334 | self.publish_update_to_parameter("output_mask", output_artifact) |
330 | 335 |
|
|
0 commit comments