From ffd078b1623f40ab868a5d07d145b5f2846a9bdb Mon Sep 17 00:00:00 2001 From: Piotr Siuszko Date: Fri, 19 Dec 2025 16:00:34 +0100 Subject: [PATCH] Resize during convert --- crates/rpack_cli/CHANGELOG.md | 7 ++++++- crates/rpack_cli/src/commands/mod.rs | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/crates/rpack_cli/CHANGELOG.md b/crates/rpack_cli/CHANGELOG.md index 3cc4220..3ec78ea 100644 --- a/crates/rpack_cli/CHANGELOG.md +++ b/crates/rpack_cli/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.2] - 2025-12-19 + +### Added + +- Resize option during conversion ## [0.1.1] - 2025-01-27 @@ -15,4 +20,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.1.0] - 2025-01-14 -- initial version \ No newline at end of file +- initial version diff --git a/crates/rpack_cli/src/commands/mod.rs b/crates/rpack_cli/src/commands/mod.rs index 260ae76..3f9ab63 100644 --- a/crates/rpack_cli/src/commands/mod.rs +++ b/crates/rpack_cli/src/commands/mod.rs @@ -66,6 +66,9 @@ pub enum Commands { /// path of the output texture #[clap(action)] output_path: PathBuf, + /// New size of the texture in pixel. + #[clap(long)] + size: Option, }, } impl Commands { @@ -109,12 +112,20 @@ impl Commands { Commands::Convert { source_path, output_path, - } => Self::convert(source_path, output_path), + size, + } => Self::convert(source_path, output_path, size), } } - fn convert(source_path: PathBuf, output_path: PathBuf) -> anyhow::Result<()> { - let image = image::open(source_path)?; + fn convert( + source_path: PathBuf, + output_path: PathBuf, + new_size: Option, + ) -> anyhow::Result<()> { + let mut image = image::open(source_path)?; + if let Some(new_size) = new_size { + image = image.resize(new_size, new_size, image::imageops::FilterType::Lanczos3); + } image.save_with_format_autodetection(output_path)?; Ok(()) }