mirror of
https://github.com/basketikun/infinite-canvas.git
synced 2026-08-05 17:04:27 +08:00
feat(canvas): 优化图片和视频节点尺寸适配
- 在 InsertAssetPayload 类型中为视频添加 width 和 height 属性 - 引入 fitNodeSize 和 nodeSizeFromRatio 工具函数处理节点尺寸计算 - 设置视频节点最大宽度和高度限制为 420px - 将原有的 fitImageNodeSize 替换为通用的 fitNodeSize 函数 - 为视频节点添加自然宽高元数据存储 - 实现视频文件上传时读取真实宽高信息 - 支持空节点在尺寸比例切换时自动调整外框大小 - 修复视频节点在生成和重试过程中的尺寸适配问题 - 统一图片和视频节点的尺寸调整逻辑 - 添加视频节点纵横比锁定功能
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
"use client";
|
||||
|
||||
export function fitNodeSize(width: number, height: number, maxWidth = 640, maxHeight = 640) {
|
||||
const w = Math.max(1, width);
|
||||
const h = Math.max(1, height);
|
||||
const scale = Math.min(1, maxWidth / w, maxHeight / h);
|
||||
return { width: w * scale, height: h * scale };
|
||||
}
|
||||
|
||||
export function nodeSizeFromRatio(size: string, baseWidth: number, baseHeight: number) {
|
||||
const match = size?.match(/^(\d+)(?:x|:)(\d+)/);
|
||||
if (!match) return null;
|
||||
const width = Number(match[1]);
|
||||
const height = Number(match[2]);
|
||||
const ratio = width / Math.max(1, height);
|
||||
if (ratio < 0.25 || ratio > 4) return { width: baseWidth, height: baseHeight };
|
||||
return ratio >= baseWidth / baseHeight ? { width: baseWidth, height: baseWidth / ratio } : { width: baseHeight * ratio, height: baseHeight };
|
||||
}
|
||||
Reference in New Issue
Block a user