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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
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
- # 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'
 
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'