mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
* Download favicons; Display first one * Refine image loading * Switch to static images * Remove unused var * Fix * Clean up * Fix width fallback
17 lines
497 B
Python
17 lines
497 B
Python
import logging
|
|
from PIL import Image
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def scale_to_max_dimensions(img, max_width, max_height):
|
|
h_to_w_ratio = img.height / img.width
|
|
w_to_h_ratio = img.width / img.height
|
|
|
|
if img.height > max_height:
|
|
img = img.resize((int(max_height * w_to_h_ratio), max_height), Image.Resampling.LANCZOS)
|
|
|
|
if img.width > max_width:
|
|
img = img.resize((max_width, int(max_width * h_to_w_ratio)), Image.Resampling.LANCZOS)
|
|
|
|
return img
|