Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subcommands Usage #81

Open
LeibnizCapital opened this issue May 4, 2021 · 3 comments
Open

Subcommands Usage #81

LeibnizCapital opened this issue May 4, 2021 · 3 comments

Comments

@LeibnizCapital
Copy link

How would I go about doing this?

magick $1 -crop \
    `magick $1 -virtual-pixel edge -blur 0x15 -fuzz 15% \
             -trim -format '%wx%h%O' info:`   +repage   $2

I'm not looking for an exact answer, just how to approach the problem. I assume two distinct wand, but I'd like to see an example.

@LeibnizCapital
Copy link
Author

LeibnizCapital commented May 4, 2021

I could swear I got the right syntax but it does not work. The command above actually trims the image which these instructions do not:

    START.call_once(|| {
        magick_wand_genesis();
    });
    let wand = MagickWand::new();
    wand.read_image(file_path).unwrap();
    wand.fit(414, 896);
    let scaled_img = wand.write_image_blob("JPEG").unwrap();
    // Trimming a blurred version of the image to catch the border correctly
    let wand_trim = MagickWand::new();
    wand_trim.read_image_blob(scaled_img).unwrap();
    wand_trim.blur_image(0_f64, 15.0).unwrap();
    wand_trim.trim_image(0.15).unwrap();
    // Same as +repage option: https://legacy.imagemagick.org/discourse-server/viewtopic.php?t=23397
    wand_trim.reset_image_page("0x0+0+0").unwrap();
    debug_assert_ne!(wand.get_image_width(), wand_trim.get_image_width());

I can see the same blur if I write the image, but no trim. What might I be missing?

@nlfiedler
Copy link
Owner

Unfortunately, this is well beyond any usage with which I have experience. One question though, does the -crop in the command example have a relevant effect? I don't see a similar operation in the Rust code, though.

@LeibnizCapital
Copy link
Author

LeibnizCapital commented May 5, 2021

There is a wand.crop_image(..) which is equivalent to crop. The problem occurs before. We blur a copy of our scan to remove make the noisy border into a uniform color then trim it. That's why we debug_assert_ne expecting the trimmed copy to be smaller as it is when running the command. Then, we crop our original scan using the dimension of the trimmed blurred copy to remove the same border: https://legacy.imagemagick.org/Usage/crop/#trim_blur. There may be a better way to do this with V7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants