feat: add option to keep aspect ratio

This commit is contained in:
PurpleMyst
2020-07-05 13:07:07 +02:00
parent c6b522a0c5
commit e3c2dca327
2 changed files with 12 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "themis" name = "themis"
version = "1.0.0" version = "1.1.0"
authors = ["PurpleMyst <PurpleMyst@users.noreply.github.com>"] authors = ["PurpleMyst <PurpleMyst@users.noreply.github.com>"]
license = "GPL-3.0-only" license = "GPL-3.0-only"
edition = "2018" edition = "2018"

View File

@@ -91,6 +91,10 @@ struct Opt {
/// The side length that the image to turn into to a mosaic will be resized to /// The side length that the image to turn into to a mosaic will be resized to
#[structopt(short, long, default_value = "128")] #[structopt(short, long, default_value = "128")]
mosaic_size: u32, mosaic_size: u32,
/// Keep the image's aspect ratio
#[structopt(short, long)]
keep_aspect_ratio: bool,
} }
fn main() -> Result<()> { fn main() -> Result<()> {
@@ -98,10 +102,16 @@ fn main() -> Result<()> {
image, image,
tiles_directory, tiles_directory,
mosaic_size, mosaic_size,
keep_aspect_ratio,
} = Opt::from_args(); } = Opt::from_args();
let possible_tiles = load_images(tiles_directory)?; 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 // For every unique pixel in the image, find its most appropiate tile
let unique_pixels = image.pixels().collect::<HashSet<_>>(); let unique_pixels = image.pixels().collect::<HashSet<_>>();