From 8ea295d1ce1d24b7da61ea823d40c50b146362d9 Mon Sep 17 00:00:00 2001 From: inorishio Date: Sat, 30 May 2026 20:40:14 +0200 Subject: [PATCH] Some prework for the binary, linter issue is resolved, unnecessary comments removed --- zshell-img-tools/.rustfmt.toml | 2 ++ zshell-img-tools/src/effects.rs | 7 ------- zshell-img-tools/src/main.rs | 31 +++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 zshell-img-tools/.rustfmt.toml diff --git a/zshell-img-tools/.rustfmt.toml b/zshell-img-tools/.rustfmt.toml new file mode 100644 index 0000000..f3e454b --- /dev/null +++ b/zshell-img-tools/.rustfmt.toml @@ -0,0 +1,2 @@ +edition = "2024" +style_edition = "2024" diff --git a/zshell-img-tools/src/effects.rs b/zshell-img-tools/src/effects.rs index fab36ab..39fa7a9 100644 --- a/zshell-img-tools/src/effects.rs +++ b/zshell-img-tools/src/effects.rs @@ -52,15 +52,11 @@ pub fn apply_shadow( blur: f32, offset_x: f32, offset_y: f32, - // blur_passes: u32, shadow_color: [u8; 4], ) -> RgbaImage { let (iw, ih) = img.dimensions(); let br = blur.ceil() as u32; let bp = 1; - // Original idea - // let spread = br * bp; - // Claude is hallucinating but let's try it **Worked btw** let spread = (br as f32 * (bp as f32).sqrt() * 2.0).ceil() as u32; let extra_left = spread + (-offset_x).max(0.0).ceil() as u32; @@ -91,11 +87,8 @@ pub fn apply_shadow( tint_pixmap_as_shadow(&mut shadow_pixmap, shadow_color); - // Shadow let shadow_img = pixmap_to_rgba_image(shadow_pixmap); - // Shadow blur let blurred = box_blur_rgba(&shadow_img, br, bp); - // Shadow pos let blurred_pixmap = rgba_image_to_pixmap(&blurred); let mut canvas = Pixmap::new(canvas_w, canvas_h).expect("canvas pixmap"); diff --git a/zshell-img-tools/src/main.rs b/zshell-img-tools/src/main.rs index 4071565..dfd0fc3 100644 --- a/zshell-img-tools/src/main.rs +++ b/zshell-img-tools/src/main.rs @@ -1,7 +1,7 @@ mod config; mod effects; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use std::io::Write as _; use std::process::{Command, Stdio}; @@ -57,7 +57,11 @@ fn extract_image_path() -> Option { } fn main() { - if let Some(path) = extract_image_path() && let Err(e) = run() { + // Fundamental issue when supplying args it won't give output unless --image is used. + // Will have to be fixed in a later patch upcoming week + if let Some(path) = extract_image_path() + && let Err(e) = run() + { eprintln!("Error: {}", e); push_image(&path).ok(); } @@ -73,6 +77,22 @@ fn run() -> Result<()> { let mut i = 0; while i < args.len() { match args[i].as_str() { + "--help" => { + println!(); + println!("Usage: zshell-img-tools [options]"); + println!(); + println!("All options are required"); + println!("Options:"); + println!(" --rounding Enable or disable rounded corners"); + println!(" --radius Set the radius for rounded corners"); + println!(" --shadow Enable or disable shadow"); + println!(" --shadow-blur Set the blur radius for the shadow"); + println!(" --shadow-offset-x Set the horizontal offset for the shadow"); + println!(" --shadow-offset-y Set the vertical offset for the shadow"); + println!(" --shadow-color Set the color of the shadow as comma-separated RGBA values (0-255)"); + println!(" --scale Scale all effects by this factor (e.g. 2.0 for display scale)"); + return Ok(()); + } "--image" => { image_path = Some(next_arg(&args, &mut i, "--image")?); } @@ -117,7 +137,11 @@ fn run() -> Result<()> { let val = next_arg(&args, &mut i, "--scale")?; scale = Some(val.parse::().context("--scale must be a number")?); } - unknown => bail!("Unknown argument: {}", unknown), + unknown => { + let unknown_args = unknown.to_string(); + println!("Warning: Unknown argument '{}'", unknown); + next_arg(&args, &mut i, &unknown_args)?; + } } i += 1; @@ -125,7 +149,6 @@ fn run() -> Result<()> { let image_path = image_path.context("Missing --image ")?; - // Check if any arguments were provided let cli_args_provided = overrides.rounding.is_some() || overrides.radius.is_some() || overrides.shadow.is_some()