feat: 添加图片适配模式支持
- 支持四种图片适配模式:stretch、contain、cover、center - 支持背景色填充功能(contain 和 center 模式) - 支持文档级 DPI 配置(metadata.dpi) - PPTX 渲染器集成 Pillow 实现高质量图片处理 - HTML 渲染器使用 CSS object-fit 实现相同效果 - 添加完整的单元测试、集成测试和端到端测试 - 更新 README 文档和架构文档 - 模块化设计:utils/image_utils.py 图片处理工具模块 - 添加图片配置验证器:validators/image_config.py - 向后兼容:未指定 fit 时默认使用 stretch 模式
This commit is contained in:
56
utils/__init__.py
Normal file
56
utils/__init__.py
Normal file
@@ -0,0 +1,56 @@
|
||||
"""
|
||||
工具函数模块
|
||||
|
||||
提供日志输出和颜色转换等通用功能。
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
# ============= 日志输出函数 =============
|
||||
|
||||
def log_info(message):
|
||||
"""输出信息日志"""
|
||||
print(f"[INFO] {message}")
|
||||
|
||||
|
||||
def log_success(message):
|
||||
"""输出成功日志"""
|
||||
print(f"[SUCCESS] ✓ {message}")
|
||||
|
||||
|
||||
def log_error(message):
|
||||
"""输出错误日志"""
|
||||
print(f"[ERROR] ✗ {message}", file=sys.stderr)
|
||||
|
||||
|
||||
def log_progress(current, total, message=""):
|
||||
"""输出进度日志"""
|
||||
print(f"[PROGRESS] {current}/{total} {message}")
|
||||
|
||||
|
||||
# ============= 颜色转换函数 =============
|
||||
|
||||
def hex_to_rgb(hex_color):
|
||||
"""
|
||||
将十六进制颜色转换为 RGB 元组
|
||||
|
||||
Args:
|
||||
hex_color: 十六进制颜色字符串,如 "#4a90e2" 或 "#fff"
|
||||
|
||||
Returns:
|
||||
tuple: (R, G, B) 元组
|
||||
"""
|
||||
hex_color = hex_color.lstrip('#')
|
||||
|
||||
# 处理短格式 #RGB -> #RRGGBB
|
||||
if len(hex_color) == 3:
|
||||
hex_color = ''.join([c*2 for c in hex_color])
|
||||
|
||||
if len(hex_color) != 6:
|
||||
raise ValueError(f"无效的颜色格式: #{hex_color}")
|
||||
|
||||
try:
|
||||
return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
|
||||
except ValueError:
|
||||
raise ValueError(f"无效的颜色格式: #{hex_color}")
|
||||
Reference in New Issue
Block a user