Skip to content

Commit

Permalink
chore: Refactor remove function to handle unsupported input types
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgatis committed Aug 4, 2024
1 parent 90536b6 commit 688b348
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions rembg/bg.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,19 @@ def remove(
"""
if isinstance(data, bytes) or force_return_bytes:
return_type = ReturnType.BYTES
img = Image.open(io.BytesIO(data))
img = Image.open(io.BytesIO(cast(bytes, data)))
elif isinstance(data, PILImage):
return_type = ReturnType.PILLOW
img = data
elif isinstance(data, np.ndarray):
return_type = ReturnType.NDARRAY
img = Image.fromarray(data)
else:
raise ValueError("Input type {} is not supported. Try using force_return_bytes=True to force python bytes output".format(type(data)))
raise ValueError(
"Input type {} is not supported. Try using force_return_bytes=True to force python bytes output".format(
type(data)
)
)

putalpha = kwargs.pop("putalpha", False)

Expand Down

0 comments on commit 688b348

Please sign in to comment.