Move to bin/ so more tools can be made.
This commit is contained in:
parent
18d19fac01
commit
8ca9e67f85
46
src/bin/perler.rs
Normal file
46
src/bin/perler.rs
Normal file
@ -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<PathBuf>,
|
||||
}
|
||||
|
||||
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<dyn Write> = if let Some(path) = opt.output {
|
||||
Box::new(File::create(path)?)
|
||||
} else {
|
||||
Box::new(io::stdout())
|
||||
};
|
||||
svg::write(w, &out_svg)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user