From b05f4b821324c6cbb02484fefa393c6601ac68a1 Mon Sep 17 00:00:00 2001 From: zihanjian Date: Mon, 26 May 2025 15:11:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=B0=8F=E7=BA=A2=E4=B9=A6?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E5=8C=BA=E5=9F=9F=EF=BC=8C=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E7=94=BB=E5=B8=83=E9=AB=98=E5=BA=A6=E8=AE=A1=E7=AE=97=EF=BC=8C?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E5=9C=A8=E4=B8=8B=E8=BD=BD=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=97=B6=E5=8C=85=E5=90=AB=E5=B0=8F=E7=BA=A2=E4=B9=A6=E6=A0=87?= =?UTF-8?q?=E8=AF=86=EF=BC=8C=E6=8F=90=E5=8D=87=E7=94=A8=E6=88=B7=E4=BD=93?= =?UTF-8?q?=E9=AA=8C=E5=92=8C=E8=A7=86=E8=A7=89=E6=95=88=E6=9E=9C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/imageDownloader.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/utils/imageDownloader.ts b/src/utils/imageDownloader.ts index 96ec2f6..96337df 100644 --- a/src/utils/imageDownloader.ts +++ b/src/utils/imageDownloader.ts @@ -110,6 +110,9 @@ export async function downloadImage({ // 计算网格尺寸 const gridWidth = N * downloadCellSize; const gridHeight = M * downloadCellSize; + + // 计算小红书标识区域的高度 + const xiaohongshuAreaHeight = 35; // 为小红书名字预留的底部空间 // 计算标题栏高度(根据图片大小自动调整) const baseTitleBarHeight = 80; // 增大基础高度 @@ -161,9 +164,9 @@ export async function downloadImage({ statsHeight = titleHeight + (numRows * statsRowHeight) + footerHeight + (statsPadding * 2) + statsTopMargin; } - // 调整画布大小,包含标题栏、坐标轴和统计区域 + // 调整画布大小,包含标题栏、坐标轴、统计区域和小红书标识区域 const downloadWidth = gridWidth + axisLabelSize + extraLeftMargin; - let downloadHeight = titleBarHeight + gridHeight + axisLabelSize + statsHeight + extraTopMargin; + let downloadHeight = titleBarHeight + gridHeight + axisLabelSize + statsHeight + extraTopMargin + xiaohongshuAreaHeight; let downloadCanvas = document.createElement('canvas'); downloadCanvas.width = downloadWidth; @@ -391,6 +394,19 @@ export async function downloadImage({ M * downloadCellSize ); + // 绘制小红书标识 - 在网格图片和统计信息之间,靠右 + const xiaohongshuFontSize = Math.max(12, Math.floor(statsFontSize * 0.9)); + ctx.fillStyle = '#E60026'; // 小红书品牌红色,更显眼 + ctx.font = `bold ${xiaohongshuFontSize}px sans-serif`; // 加粗更显眼 + ctx.textAlign = 'right'; + ctx.textBaseline = 'middle'; + + // 计算小红书标识的位置:网格下方,统计信息上方 + const xiaohongshuX = downloadWidth - 20; // 右侧留20px边距 + const xiaohongshuY = titleBarHeight + extraTopMargin + M * downloadCellSize + axisLabelSize + (xiaohongshuAreaHeight / 2); + + ctx.fillText('图纸工具:小红书@七卡瓦', xiaohongshuX, xiaohongshuY); + // 绘制统计信息 if (includeStats && colorCounts) { const colorKeys = Object.keys(colorCounts).sort(sortColorKeys); @@ -493,8 +509,8 @@ export async function downloadImage({ // 重新计算画布高度并调整 if (includeStats && colorCounts) { - // 调整画布大小,包含计算后的统计区域 - const newDownloadHeight = titleBarHeight + extraTopMargin + M * downloadCellSize + axisLabelSize + statsHeight; + // 调整画布大小,包含计算后的统计区域和小红书标识区域 + const newDownloadHeight = titleBarHeight + extraTopMargin + M * downloadCellSize + axisLabelSize + statsHeight + xiaohongshuAreaHeight; if (downloadHeight !== newDownloadHeight) { // 如果高度变化了,需要创建新的画布并复制当前内容