muhammadsalmanalfaridzi
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -494,22 +494,20 @@ def create_canvas(canvas_size, bg_choice, custom_color):
|
|
494 |
return Image.new("RGBA", canvas_size, (0, 0, 0, 0))
|
495 |
|
496 |
def apply_watermark(canvas, watermark_path):
|
497 |
-
|
498 |
-
|
499 |
-
|
|
|
|
|
500 |
|
501 |
# Calculate the position to center the watermark
|
502 |
-
|
503 |
-
|
504 |
-
x = (base_width - watermark_width) // 2
|
505 |
-
y = (base_height - watermark_height) // 2
|
506 |
|
507 |
-
#
|
508 |
-
|
509 |
-
combined.paste(base, (0, 0))
|
510 |
-
combined.paste(watermark, (x, y), watermark)
|
511 |
|
512 |
-
return
|
513 |
|
514 |
def save_image(canvas, output_folder, filename, output_format):
|
515 |
output_ext = 'jpg' if output_format == 'JPG' else 'png'
|
|
|
494 |
return Image.new("RGBA", canvas_size, (0, 0, 0, 0))
|
495 |
|
496 |
def apply_watermark(canvas, watermark_path):
|
497 |
+
watermark = Image.open(watermark_path).convert("RGBA")
|
498 |
+
|
499 |
+
# Get dimensions of both the canvas and watermark
|
500 |
+
canvas_width, canvas_height = canvas.size
|
501 |
+
watermark_width, watermark_height = watermark.size
|
502 |
|
503 |
# Calculate the position to center the watermark
|
504 |
+
x = (canvas_width - watermark_width) // 2
|
505 |
+
y = (canvas_height - watermark_height) // 2
|
|
|
|
|
506 |
|
507 |
+
# Paste the watermark on the canvas
|
508 |
+
canvas.paste(watermark, (x, y), watermark)
|
|
|
|
|
509 |
|
510 |
+
return canvas
|
511 |
|
512 |
def save_image(canvas, output_folder, filename, output_format):
|
513 |
output_ext = 'jpg' if output_format == 'JPG' else 'png'
|