polyhorn_cli/core/
rasterize.rs1use std::io::Result;
2use std::path::Path;
3
4pub fn rasterize(source: &Path, zoom: f32, destination: &Path) -> Result<()> {
7 #[cfg(feature = "embed-svg")]
8 {
9 let tree = usvg::Tree::from_file(source, &usvg::Options::default()).unwrap();
10 let image = resvg::render(&tree, usvg::FitTo::Zoom(zoom), None).unwrap();
11 image.save_png(destination).unwrap();
12 Ok(())
13 }
14
15 #[cfg(not(feature = "embed-svg"))]
16 {
17 use std::process::Command;
18
19 assert!(Command::new("resvg")
20 .arg("-z")
21 .arg(format!("{}", zoom))
22 .args(&[source, destination])
23 .status()?
24 .success());
25
26 Ok(())
27 }
28}