You've already forked FrameTour-BE
feat(watermark): 调整水印模板布局为原图完整显示
- 将原图区域从90%高度调整为100%完整高度 - 添加底部扩展10%区域用于信息展示 - 更新PuzzleDefault和PuzzlePrint模板的画布尺寸计算逻辑 - 修改二维码尺寸计算基准为原始图片高度 - 调整布局参数常量命名以反映新的设计思路
This commit is contained in:
@@ -12,8 +12,8 @@ import java.util.Map;
|
||||
*
|
||||
* 布局说明:
|
||||
* - 白色背景
|
||||
* - 顶部90%为原图区域(COVER模式)
|
||||
* - 底部10%为信息区域:
|
||||
* - 顶部100%为原图区域(COVER模式,保持原图完整尺寸)
|
||||
* - 底部扩展10%为信息区域:
|
||||
* - 左侧(距左5%):二维码(宽高为图片的8%)+ 头像(可选)
|
||||
* - 右侧(距右5%):景区名 + 日期时间(右对齐)
|
||||
*/
|
||||
@@ -23,7 +23,7 @@ public class PuzzleDefaultWatermarkTemplateBuilder extends AbstractWatermarkTemp
|
||||
public static final String STYLE = "puzzle_default";
|
||||
|
||||
// 布局比例配置
|
||||
private static final double IMAGE_HEIGHT_RATIO = 0.90; // 原图占90%高度
|
||||
private static final double BOTTOM_EXTEND_RATIO = 0.10; // 底部扩展为原图高度的10%
|
||||
private static final double MARGIN_X_RATIO = 0.05; // 左右边距为宽度的5%
|
||||
private static final double QRCODE_SIZE_RATIO = 0.08; // 二维码为图片的8%
|
||||
|
||||
@@ -43,13 +43,15 @@ public class PuzzleDefaultWatermarkTemplateBuilder extends AbstractWatermarkTemp
|
||||
int imageWidth = request.getImageWidth();
|
||||
int imageHeight = request.getImageHeight();
|
||||
|
||||
// 画布尺寸 = 原图尺寸
|
||||
int canvasWidth = imageWidth;
|
||||
int canvasHeight = imageHeight;
|
||||
// 底部扩展区域高度
|
||||
int bottomAreaHeight = (int) (imageHeight * BOTTOM_EXTEND_RATIO);
|
||||
|
||||
// 原图区域占90%高度,底部信息区占10%高度
|
||||
int originalImageHeight = (int) (imageHeight * IMAGE_HEIGHT_RATIO);
|
||||
int bottomAreaHeight = imageHeight - originalImageHeight;
|
||||
// 画布尺寸 = 原图尺寸 + 底部扩展
|
||||
int canvasWidth = imageWidth;
|
||||
int canvasHeight = imageHeight + bottomAreaHeight;
|
||||
|
||||
// 原图区域保持完整高度
|
||||
int originalImageHeight = imageHeight;
|
||||
|
||||
// 创建模板(白色背景)
|
||||
PuzzleTemplateEntity template = createTemplateWithColor(
|
||||
|
||||
@@ -13,8 +13,8 @@ import java.util.Map;
|
||||
* 布局说明:
|
||||
* - 白色背景
|
||||
* - 四周留1%白边
|
||||
* - 内部区域:顶部90%为原图区域(COVER模式)
|
||||
* - 底部10%为信息区域:
|
||||
* - 内部区域:顶部100%为原图区域(COVER模式,保持原图完整尺寸)
|
||||
* - 底部扩展10%为信息区域:
|
||||
* - 左侧(距左5%):二维码(宽高为图片的8%)+ 头像(可选)
|
||||
* - 右侧(距右5%):景区名 + 日期时间(右对齐)
|
||||
*/
|
||||
@@ -25,7 +25,7 @@ public class PuzzlePrintWatermarkTemplateBuilder extends AbstractWatermarkTempla
|
||||
|
||||
// 布局比例配置
|
||||
private static final double BORDER_RATIO = 0.01; // 四周白边为1%
|
||||
private static final double IMAGE_HEIGHT_RATIO = 0.90; // 原图占内容区90%高度
|
||||
private static final double BOTTOM_EXTEND_RATIO = 0.10; // 底部扩展为原图高度的10%
|
||||
private static final double MARGIN_X_RATIO = 0.05; // 左右边距为宽度的5%
|
||||
private static final double QRCODE_SIZE_RATIO = 0.08; // 二维码为图片的8%
|
||||
|
||||
@@ -49,21 +49,23 @@ public class PuzzlePrintWatermarkTemplateBuilder extends AbstractWatermarkTempla
|
||||
int borderX = (int) (imageWidth * BORDER_RATIO);
|
||||
int borderY = (int) (imageHeight * BORDER_RATIO);
|
||||
|
||||
// 画布尺寸 = 原图尺寸 + 四周白边
|
||||
// 底部扩展区域高度
|
||||
int bottomAreaHeight = (int) (imageHeight * BOTTOM_EXTEND_RATIO);
|
||||
|
||||
// 内容区高度 = 原图高度 + 扩展区域(扩展区域在白边内部)
|
||||
int contentHeight = imageHeight + bottomAreaHeight;
|
||||
|
||||
// 画布尺寸 = 内容区尺寸 + 四周白边
|
||||
int canvasWidth = imageWidth + borderX * 2;
|
||||
int canvasHeight = imageHeight + borderY * 2;
|
||||
int canvasHeight = contentHeight + borderY * 2;
|
||||
|
||||
// 内容区起始位置(白边内)
|
||||
int contentStartX = borderX;
|
||||
int contentStartY = borderY;
|
||||
|
||||
// 内容区尺寸 = 原图尺寸
|
||||
// 内容区宽度 = 原图宽度,原图区域保持完整高度
|
||||
int contentWidth = imageWidth;
|
||||
int contentHeight = imageHeight;
|
||||
|
||||
// 原图区域占90%高度,底部信息区占10%高度
|
||||
int originalImageHeight = (int) (contentHeight * IMAGE_HEIGHT_RATIO);
|
||||
int bottomAreaHeight = contentHeight - originalImageHeight;
|
||||
int originalImageHeight = imageHeight;
|
||||
|
||||
// 创建模板(白色背景)
|
||||
PuzzleTemplateEntity template = createTemplateWithColor(
|
||||
@@ -88,7 +90,7 @@ public class PuzzlePrintWatermarkTemplateBuilder extends AbstractWatermarkTempla
|
||||
|
||||
// 2. 计算底部区域元素位置(相对于内容区)
|
||||
int marginX = (int) (contentWidth * MARGIN_X_RATIO);
|
||||
int qrcodeSize = (int) (contentHeight * QRCODE_SIZE_RATIO); // 二维码为高度的8%
|
||||
int qrcodeSize = (int) (imageHeight * QRCODE_SIZE_RATIO); // 二维码为高度的8%
|
||||
|
||||
// 二维码垂直居中于底部区域
|
||||
int qrcodeX = contentStartX + marginX;
|
||||
|
||||
Reference in New Issue
Block a user