Aspect ratio for preview
This commit is contained in:
parent
22ce9c3f58
commit
86e9b3c600
30
roop/ui.py
30
roop/ui.py
@ -3,7 +3,12 @@ from PIL import Image, ImageTk
|
|||||||
|
|
||||||
|
|
||||||
class PreviewWindow:
|
class PreviewWindow:
|
||||||
|
|
||||||
def __init__(self, master):
|
def __init__(self, master):
|
||||||
|
self.preview_width = 600
|
||||||
|
self.preview_height = 650
|
||||||
|
|
||||||
|
|
||||||
self.master = master
|
self.master = master
|
||||||
self.window = tk.Toplevel(self.master)
|
self.window = tk.Toplevel(self.master)
|
||||||
# Override close button
|
# Override close button
|
||||||
@ -19,6 +24,10 @@ class PreviewWindow:
|
|||||||
self.frame.pack_propagate(0)
|
self.frame.pack_propagate(0)
|
||||||
self.frame.pack(fill='both', side='left', expand='True')
|
self.frame.pack(fill='both', side='left', expand='True')
|
||||||
|
|
||||||
|
# Preview image
|
||||||
|
self.img_label = tk.Label(self.frame)
|
||||||
|
self.img_label.pack(side='top')
|
||||||
|
|
||||||
# Bottom frame
|
# Bottom frame
|
||||||
buttons_frame = tk.Frame(self.frame, background="#2d3436")
|
buttons_frame = tk.Frame(self.frame, background="#2d3436")
|
||||||
buttons_frame.pack(fill='both', side='bottom')
|
buttons_frame.pack(fill='both', side='bottom')
|
||||||
@ -62,10 +71,19 @@ class PreviewWindow:
|
|||||||
return
|
return
|
||||||
|
|
||||||
img = Image.fromarray(frame)
|
img = Image.fromarray(frame)
|
||||||
img = img.resize((600, 650), Image.ANTIALIAS)
|
width, height = img.size
|
||||||
|
aspect_ratio = 1
|
||||||
|
if width > height:
|
||||||
|
aspect_ratio = self.preview_width / width
|
||||||
|
else:
|
||||||
|
aspect_ratio = self.preview_height / height
|
||||||
|
img = img.resize(
|
||||||
|
(
|
||||||
|
int(width * aspect_ratio),
|
||||||
|
int(height * aspect_ratio)
|
||||||
|
),
|
||||||
|
Image.ANTIALIAS
|
||||||
|
)
|
||||||
photo_img = ImageTk.PhotoImage(img)
|
photo_img = ImageTk.PhotoImage(img)
|
||||||
img_frame = tk.Frame(self.frame)
|
self.img_label.configure(image=photo_img)
|
||||||
img_frame.place(x=0, y=0)
|
self.img_label.image = photo_img
|
||||||
img_label = tk.Label(img_frame, image=photo_img)
|
|
||||||
img_label.image = photo_img
|
|
||||||
img_label.pack(side='top')
|
|
Loading…
Reference in New Issue
Block a user