mirror of
https://codeberg.org/JasterV/Image-Processing-CLI.git
synced 2026-04-26 18:10:07 +00:00
DynamicImage Struct implementation started
This commit is contained in:
parent
49c915ef6b
commit
9b4c3f588f
3 changed files with 56 additions and 23 deletions
|
|
@ -1,28 +1,57 @@
|
|||
use clap::{App, Arg};
|
||||
|
||||
const HELP_TEMPLATE: &str = "{bin} v{version}
|
||||
|
||||
-----------
|
||||
|
||||
{about}
|
||||
|
||||
{all-args}
|
||||
|
||||
-----------
|
||||
|
||||
(C) 2020 {author}
|
||||
|
||||
{after-help}";
|
||||
use clap::{App, Arg, ArgGroup};
|
||||
|
||||
/// This function builds the Command Line Application
|
||||
/// already with its metadata, args boundaries etc.
|
||||
pub fn build_cli() -> App<'static, 'static> {
|
||||
App::new("Image Editor application")
|
||||
// METADATA
|
||||
.author(crate_authors!())
|
||||
.version(crate_version!())
|
||||
.about("Edit, transform, crop, rotate etc. an image with just one command")
|
||||
.template(HELP_TEMPLATE)
|
||||
.before_help("Thanks for using this app bro :)")
|
||||
.after_help("Have a nice day!")
|
||||
.arg(Arg::with_name("FILE").index(1).required(true))
|
||||
// POSITIONAL ARGUMENTS
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Sets the input image file to edit")
|
||||
.index(1)
|
||||
.required(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("OUTPUT")
|
||||
.help("Sets the output path to store the image (defaults to the input + a number)")
|
||||
.required(true)
|
||||
.index(2),
|
||||
)
|
||||
// OPTIONALS GROUP, AT LEAST ONE OPTION IS REQUIRED
|
||||
.group(
|
||||
ArgGroup::with_name("options")
|
||||
.required(true)
|
||||
.multiple(true)
|
||||
.args(&["blur", "huerotate", "brighten", "contrast"]),
|
||||
)
|
||||
// OPTIONAL ARGUMENTS
|
||||
.arg(
|
||||
Arg::with_name("blur")
|
||||
.long("blur")
|
||||
.takes_value(true)
|
||||
.help("Apply blur to the image"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("huerotate")
|
||||
.long("hue-rotate")
|
||||
.takes_value(true)
|
||||
.help("Rotate the hue color scale of the image"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("brighten")
|
||||
.long("brighten")
|
||||
.takes_value(true)
|
||||
.help("Sets the brighten of the image"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("contrast")
|
||||
.long("contrast")
|
||||
.takes_value(true)
|
||||
.help("Apply contrast to the image"),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#[macro_use]
|
||||
extern crate clap;
|
||||
extern crate image;
|
||||
|
||||
pub mod cli;
|
||||
pub mod cli;
|
||||
|
|
|
|||
11
src/main.rs
11
src/main.rs
|
|
@ -1,10 +1,13 @@
|
|||
extern crate clap;
|
||||
extern crate image;
|
||||
|
||||
use lib::cli;
|
||||
use image::{DynamicImage, open};
|
||||
use lib::{cli};
|
||||
|
||||
fn main() {
|
||||
let matches = cli::build_cli().get_matches();
|
||||
|
||||
let input = matches.value_of("INPUT").unwrap();
|
||||
let output = matches.value_of("OUTPUT").unwrap();
|
||||
let image = open(input).unwrap();
|
||||
|
||||
image.save(output).unwrap();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue