muhammadsalmanalfaridzi
commited on
Commit
β’
8912dd0
1
Parent(s):
0a14b10
Update app.py
Browse files
app.py
CHANGED
@@ -410,19 +410,17 @@ def process_single_image(image_path, output_folder, bg_method, canvas_size_name,
|
|
410 |
padding_left = 50
|
411 |
|
412 |
filename = os.path.basename(image_path)
|
|
|
413 |
try:
|
414 |
print(f"Processing image: {filename}")
|
|
|
|
|
415 |
if bg_method == 'rembg':
|
416 |
image_with_no_bg = remove_background_rembg(image_path) # Placeholder for existing function
|
417 |
elif bg_method == 'bria':
|
418 |
image_with_no_bg = remove_background_bria(image_path) # Placeholder for existing function
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
# Menambahkan watermark ke gambar asli
|
423 |
-
final_image = add_watermark(original_image, watermark, position=(50, 50), transparency=128)
|
424 |
-
|
425 |
-
return final_image
|
426 |
|
427 |
temp_image_path = os.path.join(output_folder, f"temp_{filename}")
|
428 |
image_with_no_bg.save(temp_image_path, format='PNG')
|
@@ -451,11 +449,15 @@ def process_single_image(image_path, output_folder, bg_method, canvas_size_name,
|
|
451 |
output_filename = f"{os.path.splitext(filename)[0]}.{output_ext}"
|
452 |
output_path = os.path.join(output_folder, output_filename)
|
453 |
|
454 |
-
#
|
455 |
if watermark_path:
|
456 |
watermark = Image.open(watermark_path).convert("RGBA")
|
457 |
-
|
458 |
-
|
|
|
|
|
|
|
|
|
459 |
|
460 |
if output_format == 'JPG':
|
461 |
canvas.convert('RGB').save(output_path, format='JPEG')
|
|
|
410 |
padding_left = 50
|
411 |
|
412 |
filename = os.path.basename(image_path)
|
413 |
+
original_image = None # Initialize original_image to prevent reference before assignment
|
414 |
try:
|
415 |
print(f"Processing image: {filename}")
|
416 |
+
# Load the original image for watermarking
|
417 |
+
original_image = Image.open(image_path).convert("RGBA")
|
418 |
if bg_method == 'rembg':
|
419 |
image_with_no_bg = remove_background_rembg(image_path) # Placeholder for existing function
|
420 |
elif bg_method == 'bria':
|
421 |
image_with_no_bg = remove_background_bria(image_path) # Placeholder for existing function
|
422 |
+
elif bg_method == 'none':
|
423 |
+
image_with_no_bg = original_image.copy() # Load without removing background
|
|
|
|
|
|
|
|
|
|
|
424 |
|
425 |
temp_image_path = os.path.join(output_folder, f"temp_{filename}")
|
426 |
image_with_no_bg.save(temp_image_path, format='PNG')
|
|
|
449 |
output_filename = f"{os.path.splitext(filename)[0]}.{output_ext}"
|
450 |
output_path = os.path.join(output_folder, output_filename)
|
451 |
|
452 |
+
# Add watermark if applicable
|
453 |
if watermark_path:
|
454 |
watermark = Image.open(watermark_path).convert("RGBA")
|
455 |
+
image_with_no_bg.paste(watermark, (0, 0), watermark) # Add watermark on top of the image
|
456 |
+
|
457 |
+
# Save final image
|
458 |
+
output_ext = 'jpg' if output_format == 'JPG' else 'png'
|
459 |
+
output_filename = f"{os.path.splitext(filename)[0]}.{output_ext}"
|
460 |
+
output_path = os.path.join(output_folder, output_filename)
|
461 |
|
462 |
if output_format == 'JPG':
|
463 |
canvas.convert('RGB').save(output_path, format='JPEG')
|