main.rs 910 B

1234567891011121314151617181920212223242526272829303132
  1. use base64::{Engine as _, engine::general_purpose};
  2. use clap::Parser;
  3. use img2tex::convert_file;
  4. use std::fs;
  5. #[derive(Parser)]
  6. #[command(name = "img2tex")]
  7. #[command(version)]
  8. #[command(about = "Convert tile sheets to be compatible with fourteen screws engine", long_about = None)]
  9. struct Cli {
  10. /// size of a single tile in the sheet
  11. #[arg(short, long, default_value_t = 64)]
  12. tile_size: u32,
  13. /// output file
  14. #[arg(short, long, default_value_t = String::from("out.base64"))]
  15. output: String,
  16. #[arg(required=true)]
  17. image_file: String,
  18. }
  19. fn base64_encode(img: &Vec<u8>) -> String {
  20. general_purpose::STANDARD_NO_PAD.encode(img)
  21. }
  22. fn main() {
  23. let args: Cli = Cli::parse();
  24. let image_data = convert_file(&args.image_file, args.tile_size);
  25. let encoded: String = base64_encode(&image_data);
  26. fs::write(&args.output, encoded).expect(format!("unable to write output to '{}'", &args.output).as_str());
  27. }