Small Rust scripts
at main 56 lines 1.4 kB view raw
1#!/usr/bin/env -S cargo +nightly -Zscript 2 3--- 4[package] 5edition = "2024" 6[dependencies] 7argh = "0.1" 8rexiv2 = "0.9.1" 9--- 10 11// This script requires gexiv2 12// Available through: 13// (Mac) brew install gexiv2 14 15use argh::FromArgs; 16use rexiv2::Metadata; 17 18#[derive(FromArgs)] 19#[argh(description = "Show and strip EXIF data from image files.")] 20struct App { 21 #[argh(switch, description = "show EXIF info (just tags for now)")] 22 show: bool, 23 24 #[argh(switch, description = "strip EXIF info")] 25 strip: bool, 26 27 #[argh(positional, description = "path to file(s)")] 28 paths: Vec<String>, 29} 30 31fn main() { 32 let App { show, strip, paths } = argh::from_env(); 33 34 if !show && !strip { 35 eprintln!("Either --show or --strip is required"); 36 return; 37 } else if paths.is_empty() { 38 eprintln!("Must provide at least one path"); 39 return; 40 } 41 42 for path in paths { 43 let meta = Metadata::new_from_path(&path).expect("should be able to open metadata"); 44 45 if show { 46 let tags = meta.get_exif_tags().expect("should be able to get tags"); 47 println!("Available EXIF tags: {}", tags.join(", ")); 48 } 49 50 if strip { 51 println!("Clearing EXIF data from: {:?}", path); 52 meta.clear_exif(); 53 meta.save_to_file(&path).expect("should be able to resave"); 54 } 55 } 56}