Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/bria_client/toolkit/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def _process_image(self, image: ImageSource) -> Base64String | str:
if isinstance(image, str):
if image.startswith("http"):
return image
if image.startswith("data:") and ";base64," in image:
return image.split(",", 1)[-1]
if Image.is_base64(image):
return image
# infer it is a local path
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/toolkit/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ def test_image_on_init_should_work_for_all_image_source_types(self, image_source
# Assert
assert image.as_bria_api_input is not None

@pytest.mark.parametrize("prefix", ["data:image/png;base64,", "data:image/jpeg;base64,"])
def test_image_on_init_with_base64_data_uri_should_process_successfully(self, base64_image, prefix):
# Arrange
base64_with_header = f"{prefix}{base64_image}"
# Act
image = Image(base64_with_header)
# Assert
assert Image.is_base64(image.as_bria_api_input)


@pytest.mark.unit
class TestImageSource:
Expand Down