#!/usr/bin/env python3 """ Test script for full-screen image scaling functionality """ import tkinter as tk from PIL import Image, ImageTk import os def test_scaling_modes(): """Test different scaling modes for images""" def scale_image_to_screen(img, screen_width, screen_height, mode='fit'): """Test scaling function""" img_width, img_height = img.size if mode == 'stretch': return img.resize((screen_width, screen_height), Image.LANCZOS), (0, 0) elif mode == 'fill': screen_ratio = screen_width / screen_height img_ratio = img_width / img_height if img_ratio > screen_ratio: new_height = screen_height new_width = int(screen_height * img_ratio) x_offset = (screen_width - new_width) // 2 y_offset = 0 else: new_width = screen_width new_height = int(screen_width / img_ratio) x_offset = 0 y_offset = (screen_height - new_height) // 2 img_resized = img.resize((new_width, new_height), Image.LANCZOS) final_img = Image.new('RGB', (screen_width, screen_height), 'black') if new_width > screen_width: crop_x = (new_width - screen_width) // 2 img_resized = img_resized.crop((crop_x, 0, crop_x + screen_width, new_height)) x_offset = 0 if new_height > screen_height: crop_y = (new_height - screen_height) // 2 img_resized = img_resized.crop((0, crop_y, new_width, crop_y + screen_height)) y_offset = 0 final_img.paste(img_resized, (x_offset, y_offset)) return final_img, (x_offset, y_offset) else: # fit mode screen_ratio = screen_width / screen_height img_ratio = img_width / img_height if img_ratio > screen_ratio: new_width = screen_width new_height = int(screen_width / img_ratio) else: new_height = screen_height new_width = int(screen_height * img_ratio) img_resized = img.resize((new_width, new_height), Image.LANCZOS) final_img = Image.new('RGB', (screen_width, screen_height), 'black') x_offset = (screen_width - new_width) // 2 y_offset = (screen_height - new_height) // 2 final_img.paste(img_resized, (x_offset, y_offset)) return final_img, (x_offset, y_offset) # Test image path test_image = "/home/pi/Desktop/signage-player/tkinter_app/src/static/resurse/1307306470-nature_wallpaper_hd_hd_nature_3-3828209637.jpg" if not os.path.exists(test_image): print(f"Test image not found: {test_image}") return try: # Load test image img = Image.open(test_image) original_size = img.size screen_width, screen_height = 800, 600 print(f"Testing scaling modes for image: {original_size}") print(f"Target screen size: {screen_width}x{screen_height}") # Test each scaling mode modes = ['fit', 'fill', 'stretch'] for mode in modes: final_img, offset = scale_image_to_screen(img, screen_width, screen_height, mode) print(f"{mode.upper()} mode: Final size: {final_img.size}, Offset: {offset}") print("✅ All scaling modes tested successfully!") except Exception as e: print(f"❌ Error testing scaling: {e}") if __name__ == "__main__": test_scaling_modes()