gitea +
This commit is contained in:
24
frontend/remove_bg.py
Normal file
24
frontend/remove_bg.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from PIL import Image
|
||||
|
||||
def remove_background(input_path, output_path):
|
||||
try:
|
||||
img = Image.open(input_path)
|
||||
img = img.convert("RGBA")
|
||||
datas = img.getdata()
|
||||
|
||||
newData = []
|
||||
for item in datas:
|
||||
# Change all white (also shades of whites)
|
||||
# to transparent
|
||||
if item[0] > 240 and item[1] > 240 and item[2] > 240:
|
||||
newData.append((255, 255, 255, 0))
|
||||
else:
|
||||
newData.append(item)
|
||||
|
||||
img.putdata(newData)
|
||||
img.save(output_path, "PNG")
|
||||
print("Successfully removed background")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
remove_background("c:\\Users\\timo\\Documents\\Websites\\website-monitor\\frontend\\public\\logo.png", "c:\\Users\\timo\\Documents\\Websites\\website-monitor\\frontend\\public\\logo.png")
|
||||
Reference in New Issue
Block a user