nlfiedler / magick-rust

Rust bindings for ImageMagick
https://crates.io/crates/magick_rust
Apache License 2.0
259 stars 68 forks source link

Add bindings for MagickDeskewImage #94

Closed walterbm closed 2 years ago

walterbm commented 2 years ago

Add support for MagickDeskewImage to address #91

In the C implementation of MagickDeskewImage the function accepts a C float for the threshold parameter. I typed that a f64 in Rust but please let me know if you have any explicit guidance on how to convert C types.

I followed the pattern from #89 so there's no explicit unit test for this new functionality but I verified it locally with a small test project:

use magick_rust::{magick_wand_genesis, MagickWand};
use std::sync::Once;

static START: Once = Once::new();

fn process_image(path: &str) {
    let mut wand = MagickWand::new();
    wand.read_image(path).unwrap();
    wand.deskew_image(1.0).unwrap();
    wand.write_image(&format!("new-{}", path)).unwrap();
}

fn main() {
    START.call_once(|| {
        magick_wand_genesis();
    });

    let mut args = std::env::args();

    // skip binary name
    args.next();

    // image file to strip
    let path = args.next().unwrap();

    println!("path: {}", path);

    process_image(&path);
}
nlfiedler commented 2 years ago

I would assume the compiler can determine when mut is needed and when it is not.

nlfiedler commented 2 years ago

Thank you.