-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbgremover.py
More file actions
69 lines (49 loc) · 1.71 KB
/
bgremover.py
File metadata and controls
69 lines (49 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from rembg import remove
from PIL import Image, ImageTk
import tkinter as tk
from tkinter import filedialog
# Para que el ancho sea proporcional a la altura
def propor_y(x, img):
return int((x / float(img.width)) * img.height)
def open_file_dialog():
# Create the file dialog
file_path = filedialog.askopenfilename()
if not (file_path == "" or file_path is None):
# Cambiar el label1 por la ruta elegida
label1.config(text=file_path)
# Ajustamos el tamaño de la imagen
img1 = Image.open(file_path)
x = 250
y = propor_y(x, img1)
resized_img1 = img1.resize((x, y))
# Ponemos la imagen1 en la Mainwindow
tk_img1 = ImageTk.PhotoImage(resized_img1)
image1.config(image=tk_img1)
image1.image = tk_img1
# Display the selected file path in the console
print("Selected file:", file_path)
name = file_path.split("/")[-1]
output_path = "output_"+name.split(".jpg")[0]+".png"
Input = Image.open(file_path)
output = remove(Input)
output.save(output_path)
print("Finalizado")
resized_img2 = output.resize((x, y))
# Ponemos la imagen2 en la Mainwindow
tk_img2 = ImageTk.PhotoImage(resized_img2)
image2.config(image=tk_img2)
image2.image = tk_img2
window = tk.Tk()
window.title("Background Romover")
# Boton para ingresar el archivo
button = tk.Button(window, text="Eleguir Archivo", command=open_file_dialog)
button.pack()
label1 = tk.Label(window, text="")
label1.pack()
frame = tk.Frame(window)
frame.pack()
image1 = tk.Label(frame)
image1.grid(row=0, column=0)
image2 = tk.Label(frame)
image2.grid(row=0, column=1)
window.mainloop()