Extract largest preview and copy metadata over
This commit is contained in:
parent
267fdd0e29
commit
70c9d9daad
|
@ -2,14 +2,6 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "RawExtractor"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.5"
|
||||
|
@ -64,6 +56,12 @@ version = "1.0.77"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9d19de80eff169429ac1e9f48fffb163916b448a44e8e046186232046d9e1f9"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.4.12"
|
||||
|
@ -110,12 +108,64 @@ version = "1.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||
|
||||
[[package]]
|
||||
name = "gexiv2-sys"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4edf7a47be383873c52eb34426723c7c9b040f9e58cf5088f2253cef149daf1"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.151"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.71"
|
||||
|
@ -134,6 +184,26 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raw_extractor"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"rexiv2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rexiv2"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11ecb9dccad43fea1bf58ea7bb8e34614446bea8aa00f78add6624d7ee26fb87"
|
||||
dependencies = [
|
||||
"gexiv2-sys",
|
||||
"libc",
|
||||
"num-rational",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
|
|
|
@ -8,3 +8,4 @@ edition = "2021"
|
|||
[dependencies]
|
||||
anyhow = "1.0.77"
|
||||
clap = { version = "4.4.12", features = ["derive"] }
|
||||
rexiv2 = "0.10.0"
|
||||
|
|
32
src/main.rs
32
src/main.rs
|
@ -2,25 +2,45 @@
|
|||
pub mod commands;
|
||||
pub mod utils;
|
||||
|
||||
use clap::Parser;
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use rexiv2::Metadata;
|
||||
use utils::append_to_path;
|
||||
|
||||
use commands::Cli;
|
||||
|
||||
fn main() -> Result<()>{
|
||||
fn main() -> Result<()> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
for src in cli.input.iter() {
|
||||
assert!(src.is_absolute());
|
||||
let dst = match cli.output {
|
||||
Some(ref e) => e.clone(),
|
||||
None => {
|
||||
append_to_path(src.clone(), ".jpg")
|
||||
}
|
||||
None => append_to_path(src.clone(), ".jpg"),
|
||||
};
|
||||
|
||||
println!("Processing image {:?}", src);
|
||||
println!("Storing jpg to {:?}", dst);
|
||||
let metadata = Metadata::new_from_path(&src)?;
|
||||
|
||||
if let Some(previews) = metadata.get_preview_images() {
|
||||
// Get preview with highest resolution
|
||||
let preview = previews
|
||||
.iter()
|
||||
.max_by_key(|e| e.get_size())
|
||||
.expect("previews is not supposed to be empty");
|
||||
preview
|
||||
.save_to_file(&dst)
|
||||
.expect("failed to save preview to file");
|
||||
println!("Stored preview to {:?}", dst);
|
||||
|
||||
let ext = preview.get_extension().expect("failed to get extension");
|
||||
metadata
|
||||
.save_to_file(append_to_path(dst.clone(), &ext))
|
||||
.expect("failed to save metadata to file");
|
||||
println!("Stored metadata to {:?}", dst);
|
||||
} else {
|
||||
println!("Image {:?} contains no embedded JPG", src);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue