fix export bug
This commit is contained in:
@@ -144,7 +144,7 @@ fn parse_hex_color(hex: &str) -> image::Rgba<u8> {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn export_batch(images: Vec<ExportImageTask>, watermark: WatermarkSettings, output_dir: String) -> Result<String, String> {
|
||||
async fn export_batch(images: Vec<ExportImageTask>, watermark: WatermarkSettings, output_dir: String, mode: String) -> Result<String, String> {
|
||||
let font = FontRef::try_from_slice(FONT_DATA).map_err(|e| format!("Font error: {}", e))?;
|
||||
|
||||
// Note: Settings are now resolved per-task
|
||||
@@ -157,6 +157,8 @@ async fn export_batch(images: Vec<ExportImageTask>, watermark: WatermarkSettings
|
||||
let mut base_img = dynamic_img.to_rgba8();
|
||||
let (width, height) = base_img.dimensions();
|
||||
|
||||
// ONLY EXECUTE WATERMARK LOGIC IF MODE IS 'ADD'
|
||||
if mode == "add" {
|
||||
// Determine effective settings (Task > Global)
|
||||
let eff_scale = task.scale.unwrap_or(watermark.scale);
|
||||
let eff_opacity = task.opacity.unwrap_or(watermark.opacity);
|
||||
@@ -218,6 +220,8 @@ async fn export_batch(images: Vec<ExportImageTask>, watermark: WatermarkSettings
|
||||
x = x.max(0);
|
||||
y = y.max(0);
|
||||
|
||||
// SKIP DRAWING if text is empty (e.g. Remove Mode)
|
||||
if !watermark.text.trim().is_empty() {
|
||||
// 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]]);
|
||||
@@ -243,6 +247,8 @@ async fn export_batch(images: Vec<ExportImageTask>, watermark: WatermarkSettings
|
||||
&font,
|
||||
&watermark.text,
|
||||
);
|
||||
}
|
||||
} // END IF MODE == ADD
|
||||
|
||||
// Save
|
||||
let file_name = input_path.file_name().unwrap_or_default();
|
||||
|
||||
@@ -32,7 +32,9 @@ async function openFolder() {
|
||||
|
||||
async function exportBatch() {
|
||||
if (store.images.length === 0) return;
|
||||
if (!store.watermarkSettings.text) {
|
||||
|
||||
// Only require text if in ADD mode
|
||||
if (store.editMode === 'add' && !store.watermarkSettings.text) {
|
||||
alert("请输入水印文字。");
|
||||
return;
|
||||
}
|
||||
@@ -67,7 +69,8 @@ async function exportBatch() {
|
||||
await invoke('export_batch', {
|
||||
images: exportTasks,
|
||||
watermark: rustWatermarkSettings,
|
||||
outputDir: outputDir
|
||||
outputDir: outputDir,
|
||||
mode: store.editMode
|
||||
});
|
||||
alert("批量导出完成!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user