import sys
from PIL import Image
def process_image(input_path, output_path):
img = Image.open(input_path).convert("RGBA")
datas = img.getdata()
newData = []
# Convert white background to transparent
for item in datas:
# Check if the pixel color is white or close to white (tolerance)
if item[0] >= 240 and item[1] >= 240 and item[2] >= 240:
newData.append((255, 255, 255, 0)) # Replace with transparent
else:
newData.append(item)
img.putdata(newData)
img.save(output_path, "PNG")
print(f"Saved {output_path}")
if __name__ == "__main__":
if len(sys.argv) < 3:
print("Usage: python remove_bg.py