50
src/element/image.py
Normal file
50
src/element/image.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import copy
|
||||
from tkinter import *
|
||||
from PIL import ImageTk, Image, ImageOps
|
||||
|
||||
|
||||
class ImagePlaceholder:
|
||||
def __init__(self, image_window, images):
|
||||
self.current_image = None
|
||||
self.current_original_image = None
|
||||
self.image_window = image_window
|
||||
self.images = images.copy()
|
||||
|
||||
self.image_label = Label(self.image_window.window)
|
||||
self.image_label.bind('<Configure>', lambda event: self.resize_image(True))
|
||||
self.image_label.pack(side=TOP, fill=BOTH, expand=1)
|
||||
|
||||
def display_new_image(self):
|
||||
image_path = self.images[0]
|
||||
self.images.pop(0)
|
||||
self.current_original_image = Image.open(image_path)
|
||||
self.current_image = copy.deepcopy(self.current_original_image)
|
||||
self.apply_options()
|
||||
|
||||
def resize_image(self, reload=False):
|
||||
ma = self.image_window.window.winfo_toplevel()
|
||||
w, h = ma.winfo_width(), ma.winfo_height()
|
||||
|
||||
if w < 21 or h < 21:
|
||||
w = 1280
|
||||
h = 1024
|
||||
self.current_image.thumbnail((w - 20, h - 20), Image.ANTIALIAS)
|
||||
|
||||
if reload:
|
||||
self.load_widget()
|
||||
|
||||
def apply_options(self):
|
||||
self.current_image = copy.deepcopy(self.current_original_image)
|
||||
|
||||
if self.image_window.option["bw"]:
|
||||
self.current_image = self.current_image.convert("L")
|
||||
|
||||
if self.image_window.option["mirror"]:
|
||||
self.current_image = ImageOps.mirror(self.current_image)
|
||||
|
||||
self.resize_image(True)
|
||||
|
||||
def load_widget(self):
|
||||
image_to_display = ImageTk.PhotoImage(self.current_image)
|
||||
self.image_label.configure(image=image_to_display)
|
||||
self.image_label.image = image_to_display
|
Reference in New Issue
Block a user