README, config file
This commit is contained in:
+20
-7
@@ -5,7 +5,9 @@ import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List
|
||||
from PIL import Image, ImageDraw, ImageFont, ImageOps
|
||||
from tools.utils import format_relative_time, ToolError, COMMON_FONTS, get_file_info_list, sort_file_list, get_paginated_list
|
||||
import config
|
||||
from tools.utils import format_relative_time, ToolError, get_file_info_list, sort_file_list, get_paginated_list
|
||||
|
||||
|
||||
logger = logging.getLogger("MattCP")
|
||||
|
||||
@@ -43,9 +45,10 @@ async def handle(args: Dict[str, Any]):
|
||||
sort_label = sort_labels.get(sort_by, "Name (alphabetical)")
|
||||
|
||||
# Fixed grid dimensions for token optimization
|
||||
COLS = 10
|
||||
ROWS = 7
|
||||
COLS = config.CONTACT_SHEET_COLS
|
||||
ROWS = config.CONTACT_SHEET_ROWS
|
||||
PAGE_SIZE = COLS * ROWS
|
||||
|
||||
|
||||
total_files = len(file_info_list)
|
||||
paged_files = get_paginated_list(file_info_list, page, PAGE_SIZE)
|
||||
@@ -62,15 +65,25 @@ async def handle(args: Dict[str, Any]):
|
||||
|
||||
# Font loading
|
||||
font = None
|
||||
for font_candidate in COMMON_FONTS:
|
||||
# Try generic system font names first
|
||||
for font_name in config.SYSTEM_FONT_NAMES:
|
||||
try:
|
||||
font = ImageFont.truetype(font_candidate, 24)
|
||||
font = ImageFont.truetype(font_name, 24)
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
# Fallback to absolute paths
|
||||
if font is None:
|
||||
for font_path in config.FALLBACK_FONT_PATHS:
|
||||
try:
|
||||
font = ImageFont.truetype(font_path, 24)
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
if font is None:
|
||||
font = ImageFont.load_default()
|
||||
|
||||
|
||||
start_idx = (page - 1) * PAGE_SIZE
|
||||
for i, info in enumerate(paged_files):
|
||||
full_path = info["path"]
|
||||
@@ -106,8 +119,8 @@ async def handle(args: Dict[str, Any]):
|
||||
draw.text((x + 5, y + thumb_size // 2), "Error", fill=(255, 0, 0), font=font)
|
||||
|
||||
buf = io.BytesIO()
|
||||
# Save as JPEG quality 95 to save data
|
||||
canvas.save(buf, format='JPEG', quality=95)
|
||||
# Save as JPEG to save data
|
||||
canvas.save(buf, format='JPEG', quality=config.IMAGE_QUALITY)
|
||||
img_data = base64.b64encode(buf.getvalue()).decode("utf-8")
|
||||
|
||||
total_pages = (total_files + PAGE_SIZE - 1) // PAGE_SIZE
|
||||
|
||||
Reference in New Issue
Block a user