diff --git a/src/bin/perler.rs b/src/bin/perler.rs new file mode 100644 index 0000000..8c10256 --- /dev/null +++ b/src/bin/perler.rs @@ -0,0 +1,46 @@ +use std::fs::File; +use std::io; +use std::io::Write; +use std::path::PathBuf; + +use anyhow::Result; +//use image::imageops::colorops::{index_colors, BiLevel}; +//use image::math::nq::NeuQuant; +//use image::DynamicImage; +use structopt::StructOpt; + +use perler::{simplify, svgify}; + +/// Convert image to SVG in the style of perler instructions. +#[derive(StructOpt, Debug)] +#[structopt(name = "perler")] +struct Opt { + /// Input image file. + input: PathBuf, + /// Optional output .svg file. Default prints to stdout. + output: Option, +} + +fn main() -> Result<()> { + let opt = Opt::from_args(); + let img = image::open(opt.input)?; + /* + let mut img2 = img.to_rgba(); + let raw = img.into_rgba().into_raw(); + + let cmap = NeuQuant::new(1, 256, &raw); + index_colors(&mut img2, &cmap); + + let img = DynamicImage::ImageRgba8(img2.into()); + */ + let img = simplify(&img); + let out_svg = svgify(&img)?; + let w: Box = if let Some(path) = opt.output { + Box::new(File::create(path)?) + } else { + Box::new(io::stdout()) + }; + svg::write(w, &out_svg)?; + + Ok(()) +}