muhammadsalmanalfaridzi
commited on
Commit
β’
aa6b347
1
Parent(s):
66bafcc
Update app.py
Browse files
app.py
CHANGED
@@ -495,18 +495,31 @@ def create_canvas(canvas_size, bg_choice, custom_color):
|
|
495 |
|
496 |
# Function to add watermark
|
497 |
def add_watermark(image, watermark_path):
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
image.paste(watermark, (x, y), watermark)
|
508 |
return image
|
509 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
510 |
def save_image(canvas, output_folder, filename, output_format):
|
511 |
output_ext = 'jpg' if output_format == 'JPG' else 'png'
|
512 |
output_path = os.path.join(output_folder, f"{os.path.splitext(filename)[0]}.{output_ext}")
|
|
|
495 |
|
496 |
# Function to add watermark
|
497 |
def add_watermark(image, watermark_path):
|
498 |
+
if watermark_path:
|
499 |
+
watermark = Image.open(watermark_path).convert("RGBA")
|
500 |
+
width, height = image.size
|
501 |
+
watermark = watermark.resize((width // 4, height // 4), Image.ANTIALIAS) # Resize watermark
|
502 |
+
w_width, w_height = watermark.size
|
503 |
+
|
504 |
+
# Position the watermark in the center
|
505 |
+
position = ((width - w_width) // 2, (height - w_height) // 2)
|
506 |
+
image.paste(watermark, position, watermark)
|
|
|
507 |
return image
|
508 |
+
|
509 |
+
def process_image(image_path, watermark_path):
|
510 |
+
try:
|
511 |
+
# Menghapus latar belakang
|
512 |
+
image_without_bg = remove_background_bria(image_path)
|
513 |
+
if image_without_bg is None:
|
514 |
+
raise Exception("Background removal failed.")
|
515 |
+
|
516 |
+
# Menambahkan watermark
|
517 |
+
final_image = add_watermark(image_without_bg, watermark_path)
|
518 |
+
return final_image
|
519 |
+
except Exception as e:
|
520 |
+
print(f"Error processing image: {e}")
|
521 |
+
return None
|
522 |
+
|
523 |
def save_image(canvas, output_folder, filename, output_format):
|
524 |
output_ext = 'jpg' if output_format == 'JPG' else 'png'
|
525 |
output_path = os.path.join(output_folder, f"{os.path.splitext(filename)[0]}.{output_ext}")
|