watermark pos bug

This commit is contained in:
Julian Freeman
2026-01-19 00:12:04 -04:00
parent 54408a5933
commit a0822153c1
4 changed files with 29 additions and 32 deletions

View File

@@ -153,9 +153,9 @@ async fn export_batch(images: Vec<ExportImageTask>, watermark: WatermarkSettings
let mut base_img = dynamic_img.to_rgba8();
let (width, height) = base_img.dimensions();
// 1. Calculate Font Scale
// watermark.scale is percentage of image height. e.g. 0.05
let mut scale_px = height as f32 * watermark.scale as f32;
// 1. Calculate Font Scale based on Min Dimension (Consistent relative size)
let min_dim = width.min(height) as f32;
let mut scale_px = min_dim * watermark.scale as f32;
// 2. Measure Text
let scaled_font = PxScale::from(scale_px);
@@ -176,7 +176,7 @@ async fn export_batch(images: Vec<ExportImageTask>, watermark: WatermarkSettings
} else {
match calculate_zca_internal(&dynamic_img) {
Ok(res) => (res.x, res.y),
Err(_) => (0.5, 0.96),
Err(_) => (0.5, 0.99),
}
};
@@ -188,7 +188,7 @@ async fn export_batch(images: Vec<ExportImageTask>, watermark: WatermarkSettings
let mut y = (center_y - (final_t_height as f64 / 2.0)) as i32;
// 5. Boundary Clamping (Ensure text stays inside image with padding)
let padding = (height as f64 * 0.01).max(5.0) as i32; // 1% padding
let padding = (height as f64 * 0.005).max(2.0) as i32; // 0.5% padding, min 2px
let max_x = (width as i32 - final_t_width as i32 - padding).max(padding);
let max_y = (height as i32 - final_t_height as i32 - padding).max(padding);
@@ -255,7 +255,7 @@ fn calculate_zca_internal(img: &image::DynamicImage) -> Result<ZcaResult, String
let mut min_std_dev = f64::MAX;
let mut best_zone = "Center";
let mut best_pos = (0.5, 0.95);
let mut best_pos = (0.5, 0.99);
for (name, start_x, start_y) in zones.iter() {
let mut luma_values = Vec::with_capacity((zone_width * zone_height) as usize);
@@ -281,7 +281,9 @@ fn calculate_zca_internal(img: &image::DynamicImage) -> Result<ZcaResult, String
min_std_dev = std_dev;
best_zone = name;
let center_x_px = *start_x as f64 + (zone_width as f64 / 2.0);
let center_y_px = *start_y as f64 + (zone_height as f64 * 0.75);
// Position closer to bottom
// 0.8 + 0.2 * 0.95 = 0.99
let center_y_px = *start_y as f64 + (zone_height as f64 * 0.95);
best_pos = (center_x_px / width as f64, center_y_px / height as f64);
}
}