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/),
|
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).
|
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
|
## [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
|
## [0.1.0] - 2025-01-14
|
||||||
|
|
||||||
- initial version
|
- initial version
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,9 @@ pub enum Commands {
|
||||||
/// path of the output texture
|
/// path of the output texture
|
||||||
#[clap(action)]
|
#[clap(action)]
|
||||||
output_path: PathBuf,
|
output_path: PathBuf,
|
||||||
|
/// New size of the texture in pixel.
|
||||||
|
#[clap(long)]
|
||||||
|
size: Option<u32>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
impl Commands {
|
impl Commands {
|
||||||
|
|
@ -109,12 +112,20 @@ impl Commands {
|
||||||
Commands::Convert {
|
Commands::Convert {
|
||||||
source_path,
|
source_path,
|
||||||
output_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<()> {
|
fn convert(
|
||||||
let image = image::open(source_path)?;
|
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)?;
|
image.save_with_format_autodetection(output_path)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue