seperate size
This commit is contained in:
@@ -107,6 +107,8 @@ struct ZcaResult {
|
||||
struct ExportImageTask {
|
||||
path: String,
|
||||
manual_position: Option<ManualPosition>,
|
||||
scale: Option<f64>,
|
||||
opacity: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
@@ -141,11 +143,7 @@ async fn export_batch(images: Vec<ExportImageTask>, watermark: WatermarkSettings
|
||||
let font = FontRef::try_from_slice(FONT_DATA).map_err(|e| format!("Font error: {}", e))?;
|
||||
let base_color = parse_hex_color(&watermark.color);
|
||||
|
||||
// Calculate final color with opacity
|
||||
// imageproc draws with the exact color given. To support opacity, we need to handle it.
|
||||
// However, draw_text_mut blends. If we provide an Rgba with alpha < 255, it should blend.
|
||||
let alpha = (watermark.opacity * 255.0) as u8;
|
||||
let text_color = image::Rgba([base_color[0], base_color[1], base_color[2], alpha]);
|
||||
// Note: opacity and final text color are now calculated per-task
|
||||
|
||||
let results: Vec<Result<(), String>> = images.par_iter().map(|task| {
|
||||
let input_path = Path::new(&task.path);
|
||||
@@ -155,8 +153,16 @@ async fn export_batch(images: Vec<ExportImageTask>, watermark: WatermarkSettings
|
||||
let mut base_img = dynamic_img.to_rgba8();
|
||||
let (width, height) = base_img.dimensions();
|
||||
|
||||
// Determine effective settings (Task > Global)
|
||||
let eff_scale = task.scale.unwrap_or(watermark.scale);
|
||||
let eff_opacity = task.opacity.unwrap_or(watermark.opacity);
|
||||
|
||||
// Calculate final color with effective opacity
|
||||
let alpha = (eff_opacity * 255.0) as u8;
|
||||
let text_color = image::Rgba([base_color[0], base_color[1], base_color[2], alpha]);
|
||||
|
||||
// 1. Calculate Font Scale based on Image Height
|
||||
let mut scale_px = height as f32 * watermark.scale as f32;
|
||||
let mut scale_px = height as f32 * eff_scale as f32;
|
||||
|
||||
// 2. Measure Text
|
||||
let scaled_font = PxScale::from(scale_px);
|
||||
@@ -207,6 +213,7 @@ async fn export_batch(images: Vec<ExportImageTask>, watermark: WatermarkSettings
|
||||
y = y.max(0);
|
||||
|
||||
// 6. Draw Stroke (Simple 4-direction offset for black outline)
|
||||
// Stroke alpha should match text alpha
|
||||
let stroke_color = image::Rgba([0, 0, 0, text_color[3]]);
|
||||
for offset in [(-1, -1), (-1, 1), (1, -1), (1, 1)] {
|
||||
draw_text_mut(
|
||||
|
||||
Reference in New Issue
Block a user