mirror of https://github.com/Leinnan/rpack.git
Resize during convert
This commit is contained in:
parent
8d64b9e639
commit
ffd078b162
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue