├── .gitignore
├── example
├── rust_input.png
├── qrcode_input.png
├── qrcode_output.svg
├── qrcode_output_source.txt
├── rust_output.svg
└── rust_output_source.txt
├── Cargo.toml
├── src
├── cli.yml
└── main.rs
├── README.md
└── LICENSE.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | .cargo/
2 | .vscode/
3 | target/
4 | Cargo.lock
5 |
--------------------------------------------------------------------------------
/example/rust_input.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/STPR/raster2svg/HEAD/example/rust_input.png
--------------------------------------------------------------------------------
/example/qrcode_input.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/STPR/raster2svg/HEAD/example/qrcode_input.png
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "raster2svg"
3 | version = "1.0.14"
4 | authors = ["STPR"]
5 | edition = "2021"
6 | rust-version = "1.58.1"
7 | description = "A tool that use the contour_tracing library."
8 | homepage = "https://github.com/STPR/raster2svg"
9 | repository = "https://github.com/STPR/raster2svg"
10 | readme = "README.md"
11 | keywords = ["contour_tracing", "contour", "boundary", "tracing", "algorithm"]
12 | categories = ["algorithms", "graphics", "multimedia::encoding", "multimedia::images"]
13 | license = "EUPL-1.2"
14 | exclude = [".gitignore", "example/*"]
15 |
16 | [[bin]]
17 | name = "raster2svg"
18 | path = "src/main.rs"
19 |
20 | [profile.release]
21 | lto = true
22 | #panic = "abort"
23 | codegen-units = 1
24 |
25 | [dependencies]
26 | image = "0.24.1"
27 | contour_tracing = { version = "1.0.12", features = ["array"] }
28 |
29 | [dependencies.clap]
30 | version = "2.34.0"
31 | default-features = false
32 | features = ["yaml"]
33 |
--------------------------------------------------------------------------------
/example/qrcode_output.svg:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/example/qrcode_output_source.txt:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/src/cli.yml:
--------------------------------------------------------------------------------
1 | name: raster2svg
2 | version: "1.0.14"
3 | author: "Copyright (c) 2022, STPR - https://github.com/STPR"
4 | about: "For more information, please visit https://crates.io/crates/raster2svg"
5 | args:
6 | - size:
7 | display_order: 1
8 | short: s
9 | long: size
10 | help: "Add the width, height and viewBox attributes"
11 | - PERCENT:
12 | display_order: 2
13 | short: z
14 | long: zoom
15 | help: "Multiply the width and height attributes by a given percent (e.g. 250)"
16 | takes_value: true
17 | requires:
18 | - size
19 | - COLOR:
20 | display_order: 3
21 | short: l
22 | long: color
23 | help: "Trace only one given color in hex notation RRGGBBAA (e.g. 112233FF)"
24 | takes_value: true
25 | conflicts_with:
26 | - AVCOLOR
27 | - AVCOLOR:
28 | display_order: 4
29 | short: a
30 | long: avcolor
31 | help: "Avoid a given color in hex notation RRGGBBAA (e.g. 112233FF)"
32 | takes_value: true
33 | conflicts_with:
34 | - COLOR
35 | - BGCOLOR:
36 | display_order: 5
37 | short: b
38 | long: bgcolor
39 | help: "Add a background rectangle with a given color in hex notation RRGGBBAA (e.g. 112233FF)"
40 | takes_value: true
41 | - ids:
42 | display_order: 6
43 | short: d
44 | long: ids
45 | help: "Add the RGB colors and opacity values as id attributes"
46 | - inkscape:
47 | display_order: 7
48 | short: k
49 | long: inkscape
50 | help: "Add some Inkscape attributes (transparent background, pixel units, grid, snapping, ...)"
51 | - rendering:
52 | display_order: 8
53 | short: r
54 | long: rendering
55 | help: "Set the shape-rendering attribute to crispEdges"
56 | - closepaths:
57 | display_order: 9
58 | short: c
59 | long: closepaths
60 | help: "Close the paths with the SVG Path Z command"
61 | - INPUT:
62 | display_order: 10
63 | short: i
64 | long: input
65 | help: "Input raster image filename (e.g. input.png)"
66 | required: true
67 | takes_value: true
68 | - OUTPUT:
69 | display_order: 11
70 | short: o
71 | long: output
72 | help: "Output SVG filename (e.g. output.svg)"
73 | required: true
74 | takes_value: true
75 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # raster2svg [![crates.io][cratesio-img]][cratesio-url]
2 |
3 | A tool that use the contour_tracing library [![Package][package-img]][package-url]
4 |
5 | ## Features
6 |
7 | - Support **RGB colors + alpha channel** (fully transparent colors are not traced)
8 | - Sort the colors from the most used to the less used
9 | - Input format: a raster image file
10 | - Output format: an SVG file
11 |
12 | Features from the contour_tracing library: [![Package][package-img]][package-url]
13 | - Trace contours using the Theo Pavlidis' algorithm (connectivity: 4-connected)
14 | - Trace **outlines** in **clockwise direction**
15 | - Trace **holes** in **counterclockwise direction**
16 |
17 | ## Options
18 | ```
19 | -s, --size Add the width, height and viewBox attributes
20 | -d, --ids Add the RGB colors and opacity values as id attributes
21 | -k, --inkscape Add some Inkscape attributes (transparent background, pixel units, grid, snapping, ...)
22 | -r, --rendering Set the shape-rendering attribute to crispEdges
23 | -c, --closepaths Close the paths with the SVG Path Z command
24 |
25 | -z, --zoom Multiply the width and height attributes by a given percent (e.g. 250)
26 | -l, --color Trace only one given color in hex notation RRGGBBAA (e.g. 112233FF)
27 | -a, --avcolor Avoid a given color in hex notation RRGGBBAA (e.g. 112233FF)
28 | -b, --bgcolor Add a background rectangle with a given color in hex notation RRGGBBAA (e.g. 112233FF)
29 | -i, --input Input raster image filename (e.g. input.png)
30 | -o, --output