muhammadsalmanalfaridzi commited on
Commit
f86bf66
·
verified ·
1 Parent(s): b911b9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -494,13 +494,22 @@ 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
- watermark = Image.open(watermark_path).convert("RGBA")
498
-
 
 
499
  # Calculate the position to center the watermark
500
- x = (canvas_width - watermark_width) // 2
501
- y = (canvas_height - watermark_height) // 2
 
 
 
 
 
 
 
502
 
503
- canvas.paste(watermark, (x, y), watermark)
504
 
505
  def save_image(canvas, output_folder, filename, output_format):
506
  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
+ # Open the images
498
+ base = canvas.convert("RGBA")
499
+ watermark = watermark.convert("RGBA")
500
+
501
  # Calculate the position to center the watermark
502
+ base_width, base_height = base.size
503
+ watermark_width, watermark_height = watermark.size
504
+ x = (base_width - watermark_width) // 2
505
+ y = (base_height - watermark_height) // 2
506
+
507
+ # Create a new image with an alpha layer for transparency
508
+ combined = Image.new("RGBA", base.size)
509
+ combined.paste(base, (0, 0))
510
+ combined.paste(watermark, (x, y), watermark)
511
 
512
+ return combined.convert("RGB") # Convert back to RGB if needed
513
 
514
  def save_image(canvas, output_folder, filename, output_format):
515
  output_ext = 'jpg' if output_format == 'JPG' else 'png'