From e3c2dca3277106b92eb069612e6d84d9acebd787 Mon Sep 17 00:00:00 2001 From: PurpleMyst Date: Sun, 5 Jul 2020 13:07:07 +0200 Subject: [PATCH] feat: add option to keep aspect ratio --- Cargo.toml | 2 +- src/main.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 664704a..3653216 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "themis" -version = "1.0.0" +version = "1.1.0" authors = ["PurpleMyst "] license = "GPL-3.0-only" edition = "2018" diff --git a/src/main.rs b/src/main.rs index afbe8cf..2c0f787 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,6 +91,10 @@ struct Opt { /// The side length that the image to turn into to a mosaic will be resized to #[structopt(short, long, default_value = "128")] mosaic_size: u32, + + /// Keep the image's aspect ratio + #[structopt(short, long)] + keep_aspect_ratio: bool, } fn main() -> Result<()> { @@ -98,10 +102,16 @@ fn main() -> Result<()> { image, tiles_directory, mosaic_size, + keep_aspect_ratio, } = Opt::from_args(); let possible_tiles = load_images(tiles_directory)?; - let image = image::open(image)?.thumbnail_exact(mosaic_size, mosaic_size); + let image = image::open(image)?; + let image = if keep_aspect_ratio { + image.thumbnail(mosaic_size, mosaic_size) + } else { + image.thumbnail_exact(mosaic_size, mosaic_size) + }; // For every unique pixel in the image, find its most appropiate tile let unique_pixels = image.pixels().collect::>();