DynamicImage Struct implementation started

This commit is contained in:
Víctor Martínez 2020-11-22 20:55:02 +01:00
parent 49c915ef6b
commit 9b4c3f588f
3 changed files with 56 additions and 23 deletions

View file

@ -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"),
)
}

View file

@ -1,4 +1,5 @@
#[macro_use]
extern crate clap;
extern crate image;
pub mod cli;
pub mod cli;

View file

@ -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();
}