issue
Browse files
image/remove_background.py
CHANGED
|
@@ -27,21 +27,21 @@ class RemoveBackground(ImageBase):
|
|
| 27 |
# Validate input
|
| 28 |
self._validate_input_file()
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
output_path = self._generate_output_path()
|
| 32 |
|
| 33 |
logger_config.info(f"Removing background from: {self.input_file_path}")
|
| 34 |
|
| 35 |
with open(self.input_file_path, 'rb') as infile:
|
| 36 |
input_image = infile.read()
|
| 37 |
|
| 38 |
-
# Perform background removal
|
| 39 |
output_image = remove(input_image)
|
| 40 |
|
| 41 |
with open(output_path, 'wb') as outfile:
|
| 42 |
outfile.write(output_image)
|
| 43 |
|
| 44 |
-
logger_config.info(f"Background removed successfully: {output_path}")
|
| 45 |
|
| 46 |
return output_path
|
| 47 |
|
|
|
|
| 27 |
# Validate input
|
| 28 |
self._validate_input_file()
|
| 29 |
|
| 30 |
+
# Always output as PNG to preserve transparency
|
| 31 |
+
output_path = self._generate_output_path('png')
|
| 32 |
|
| 33 |
logger_config.info(f"Removing background from: {self.input_file_path}")
|
| 34 |
|
| 35 |
with open(self.input_file_path, 'rb') as infile:
|
| 36 |
input_image = infile.read()
|
| 37 |
|
| 38 |
+
# Perform background removal - rembg outputs RGBA with transparency
|
| 39 |
output_image = remove(input_image)
|
| 40 |
|
| 41 |
with open(output_path, 'wb') as outfile:
|
| 42 |
outfile.write(output_image)
|
| 43 |
|
| 44 |
+
logger_config.info(f"Background removed successfully (transparent PNG): {output_path}")
|
| 45 |
|
| 46 |
return output_path
|
| 47 |
|