diff --git a/README.md b/README.md index 8913141..a60d3dc 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,13 @@ Catwalk makes it easy to generate [beautiful preview images](https://raw.githubu You can install Catwalk using one of the methods below: -| Installation Method | Instructions | -| ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -| crates.io | `cargo install catppuccin-catwalk` | -| Source | `cargo install --git https://github.com/catppuccin/catwalk catppuccin-catwalk` | -| Homebrew | `brew install catppuccin/tap/catwalk` | +| Installation Method | Instructions | +| ------------------------------------- | --------------------------------------------------------------------------------------------------------------- | +| crates.io | `cargo install catppuccin-catwalk` | +| Source | `cargo install --git https://github.com/catppuccin/catwalk catppuccin-catwalk` | +| Homebrew | `brew install catppuccin/tap/catwalk` | | Nix | `nix profile install github:catppuccin/catwalk`
`nix run github:catppuccin/catwalk -- [OPTIONS] ` | -| Binaries
(Windows, MacOS & Linux) | Available from the [latest GitHub release](https://github.com/catppuccin/catwalk/releases). | +| Binaries
(Windows, MacOS & Linux) | Available from the [latest GitHub release](https://github.com/catppuccin/catwalk/releases). | ## Usage @@ -53,7 +53,7 @@ Arguments: Options: -o, --output Path to output file [default: ./preview.webp] - -l, --layout Layout to use [default: composite] [possible values: composite, stacked, grid, row] + -l, --layout Layout to use [default: composite] [possible values: composite, stacked, grid, row, column] -r, --radius Radius of rounded corners (percentage) -g, --gap Size of gaps between pictures for the `grid` layout -C, --directory Change to before processing files [default: .] @@ -65,11 +65,11 @@ Options: ### Examples ```console -$ catwalk latte.webp frappe.webp macchiato.webp mocha.webp --output catwalk.webp +catwalk latte.webp frappe.webp macchiato.webp mocha.webp --output catwalk.webp ``` ```console -$ catwalk latte.png frappe.png macchiato.png mocha.png --directory ./assets/ +catwalk latte.png frappe.png macchiato.png mocha.png --directory ./assets/ ```   diff --git a/src/lib.rs b/src/lib.rs index 112c431..a71d1cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,11 +23,13 @@ pub enum Layout { Stacked, Grid, Row, + Column, } enum GridLayouts { Grid, Row, + Column, } #[derive(thiserror::Error, Debug)] @@ -229,14 +231,10 @@ impl Magic { fn gen_grid(&self, layout: &GridLayouts) -> Image { // Round images let gap = self.gap; - let rounded: Vec> = self - .images - .iter() - .map(|x| self.rounding_mask.mask(x)) - .collect(); + let rounded = self.images.iter().map(|x| self.rounding_mask.mask(x)); - // Create final - let mut result = match layout { + // Create a blank image canvas to place each image into. + let mut canvas = match layout { GridLayouts::Grid => Image::new( (self.width * 2) + (gap * 3), (self.height * 2) + (gap * 3), @@ -247,25 +245,34 @@ impl Magic { self.height + (gap * 2), Rgba::transparent(), ), + GridLayouts::Column => Image::new( + (self.width) + gap, + (self.height * 4) + (gap * 5), + Rgba::transparent(), + ), } .with_overlay_mode(OverlayMode::Merge); - // calculate the top left coordinates for each image, and paste - rounded.iter().enumerate().for_each(|(i, img)| { + + // calculate the top left coordinates for each image, and copy + // their image data into the canvas. + rounded.enumerate().for_each(|(i, img)| { let x = match layout { GridLayouts::Row => i % 4, GridLayouts::Grid => i % 2, + GridLayouts::Column => 0, }; let y = match layout { GridLayouts::Row => 0, GridLayouts::Grid => i / 2, + GridLayouts::Column => i % 4, }; - result.paste( + canvas.paste( gap + (self.width + gap) * x as u32, gap + (self.height + gap) * y as u32, - img, + &img, ); }); - result + canvas } /// Generates a mask for the given image. fn gen_mask(w: f32, index: usize, aa_level: u32, inverse_slope: f32) -> TrapMask { @@ -288,6 +295,7 @@ impl Magic { Layout::Stacked => self.gen_stacked(), Layout::Grid => self.gen_grid(&GridLayouts::Grid), Layout::Row => self.gen_grid(&GridLayouts::Row), + Layout::Column => self.gen_grid(&GridLayouts::Column), } }