()
| 27 | |
| 28 | # -------------------------- LOAD IMAGE AND CHECK FILE TYPE ON IMAGE CANVAS (use Frame) -------------- |
| 29 | def load_image(): |
| 30 | global img, loaded_image, image_canvas |
| 31 | |
| 32 | file_path = filedialog.askopenfilename( |
| 33 | filetypes=[("Image files", "*.jpg *.jpeg *.png *.bmp")] |
| 34 | ) |
| 35 | if not file_path: |
| 36 | return |
| 37 | |
| 38 | img = Image.open(file_path) |
| 39 | max_width, max_height = 800, 600 |
| 40 | if img.width > max_width or img.height > max_height: |
| 41 | ratio = min(max_width / img.width, max_height / img.height) |
| 42 | resize_img = img.resize( |
| 43 | (int(img.width * ratio), int(img.height * ratio)), Image.Resampling.LANCZOS |
| 44 | ) |
| 45 | loaded_image = ImageTk.PhotoImage(resize_img) |
| 46 | |
| 47 | window.geometry(f"{resize_img.width + 300 + 30}x{resize_img.height + 50}") |
| 48 | image_canvas.config(width=resize_img.width, height=resize_img.height) |
| 49 | image_canvas.grid(row=0, column=1, padx=20, pady=20, columnspan=2) |
| 50 | image_canvas.create_image(0, 0, anchor="nw", image=loaded_image) |
| 51 | else: |
| 52 | loaded_image = ImageTk.PhotoImage(img) |
| 53 | window.geometry(f"{img.width + 300}x{img.height + 50}") |
| 54 | image_canvas.config(width=img.width, height=img.height) |
| 55 | image_canvas.grid(row=0, column=1, padx=20, pady=20, columnspan=2) |
| 56 | image_canvas.create_image(0, 0, anchor="nw", image=loaded_image) |
| 57 | |
| 58 | |
| 59 | # ------------------------------------- DRAG AND DROP FEATURE -------- |
nothing calls this directly
no outgoing calls
no test coverage detected