commit a3f43bd6eb1b0c1fae893727a64f311459554ca0
parent 1732c2909604aef826749c0399019bb1e5629cfa
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date: Sun, 14 Oct 2018 14:34:36 -0400
Merge branch 'master'.
Diffstat:
5 files changed, 41 insertions(+), 25 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,4 +1,11 @@
-/target
-**/*.rs.bk
-.bak
-*.svg-
\ No newline at end of file
+# Ignore all.
+*
+
+# Git files.
+!.gitignore
+!README.org
+
+# Cargo and code.
+!Cargo.toml
+!src
+!src/*+
\ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
@@ -1,14 +0,0 @@
-[[package]]
-name = "logo"
-version = "0.1.0"
-dependencies = [
- "svg 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "svg"
-version = "0.5.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[metadata]
-"checksum svg 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "5ce4450d6982b758228fa5407db2fc27cefccb013c170ade23c03ec3a643bb72"
diff --git a/Cargo.toml b/Cargo.toml
@@ -1,7 +1,11 @@
[package]
name = "logo"
-version = "0.1.0"
-authors = ["Shimmy Xu <shimmy1996@users.noreply.github.com>"]
+version = "0.2.0"
+authors = []
[dependencies]
-svg = "0.5.10"-
\ No newline at end of file
+svg = "0.5.10"
+
+[dependencies.resvg]
+version = "0.3.0"
+features = ["cairo-backend"]+
\ No newline at end of file
diff --git a/README.org b/README.org
@@ -1,3 +1,3 @@
* Logo
A simple script that generates my avatar icon thingy in any given size.
-Output format is =.svg=.
+Output formats are =.svg= and =.png=.
diff --git a/src/main.rs b/src/main.rs
@@ -1,9 +1,12 @@
+extern crate resvg;
extern crate svg;
use std::cmp;
use std::io;
+use std::path::Path;
use std::vec::Vec;
+use resvg::usvg;
use svg::node::element::Polygon;
use svg::node::element::Rectangle;
use svg::Document;
@@ -17,9 +20,14 @@ fn print_points(points: &Vec<(f64, f64)>) -> String {
}
fn main() -> io::Result<()> {
+ // Color Pallette
let primary_color = "#700000";
let secondary_color = "#707070";
+ // Output Path
+ let svg_path = "logo.svg";
+ let png_path = "logo.png";
+ // Parse user inputs.
let mut input = String::new();
println!("Desired width:");
io::stdin().read_line(&mut input)?;
@@ -29,6 +37,7 @@ fn main() -> io::Result<()> {
io::stdin().read_line(&mut input)?;
let height = input.trim().parse::<i32>().unwrap();
+ // Draw logo and save svg.
let unit: f64 = (cmp::min(width, height) as f64) / 10.;
let center: (f64, f64) = ((width as f64) / 2., (height as f64) / 2.);
let top_touch: f64 = center.0 + 2. / 3. * center.1 - 2. * unit;
@@ -79,6 +88,16 @@ fn main() -> io::Result<()> {
.add(flare)
.add(star);
- svg::save("logo.svg", &document).unwrap();
+ svg::save(svg_path, &document).unwrap();
+
+ // Convert to png.
+ let _resvg = resvg::init();
+ let mut opt = resvg::Options::default();
+ opt.usvg.path = Some(svg_path.clone().into());
+ let rtree = usvg::Tree::from_file(svg_path, &opt.usvg).unwrap();
+ let backend = resvg::default_backend();
+ let img = backend.render_to_image(&rtree, &opt).unwrap();
+ img.save(Path::new(png_path));
+
Ok(())
}