Skip to content

Commit 37e0e10

Browse files
author
Sam Reis
committed
add Badge::to_svg_data_uri method
1 parent 905650e commit 37e0e10

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

Cargo.lock

Lines changed: 22 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/badge/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ documentation = "https://docs.rs/badge"
1111
path = "badge.rs"
1212

1313
[dependencies]
14+
base64 = "0.9.0"
1415
rusttype = "0.4.0"

src/web/badge/badge.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//! Simple badge generator
22
3+
extern crate base64;
34
extern crate rusttype;
45

56

7+
use base64::display::Base64Display;
68
use rusttype::{Font, FontCollection, Scale, point, Point, PositionedGlyph};
79

810

@@ -60,6 +62,12 @@ impl Badge {
6062
}
6163

6264

65+
pub fn to_svg_data_uri(&self) -> String {
66+
format!("data:image/svg+xml;base64,{}",
67+
Base64Display::standard(self.to_svg().as_bytes()))
68+
}
69+
70+
6371
pub fn to_svg(&self) -> String {
6472
let left_width = self.calculate_width(&self.options.subject) + 6;
6573
let right_width = self.calculate_width(&self.options.status) + 6;

0 commit comments

Comments
 (0)