Resize during convert

This commit is contained in:
Piotr Siuszko 2025-12-19 16:00:34 +01:00
parent 8d64b9e639
commit ffd078b162
2 changed files with 20 additions and 4 deletions

View File

@ -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

View File

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