The OpenBadge Project
Why
SVG badges are pretty awesome, but the current solutions (eg: shield.io, fury.io) are somewhat heavy.
Sometimes you need to run custom functionality, sometimes the source data to generate lives behind firewalls, and sometimes hackers just want to hack.
The Open Badge project gives you a module that produces custom SVG badges, giving you full control over fonts, sizes, padding, colors, etc.
It's pretty lightweight, so you can include it as part of your projects. Pure SVG solution. Does not require canvas libraries to be installed on your system.
Runnable Example usage in an express app:
var app = require('express')(),
openBadge = require('./');
app.get('/simple.svg', function (req, res) {
openBadge({text: ['Accident Free', '20 Days']}, function (err, badgeSvg) {
res.set('Content-Type', 'image/svg+xml');
res.send(badgeSvg);
});
});
app.get('/font.svg', function (req, res) {
openBadge({text: ['Favorite Font', 'Comic Sans'], font: {fontFace: 'fonts/comic-sans/comic-sans.ttf'}}, function (err, badgeSvg) {
res.set('Content-Type', 'image/svg+xml');
res.send(badgeSvg);
});
});
app.get('/colors.svg', function (req, res) {
openBadge({text: ['Pretty', 'Colors!'], color:{left:"#ccc",right:"#cc99ff",font:"#333",shadow:"#fff"}}, function (err, badgeSvg) {
res.set('Content-Type', 'image/svg+xml');
res.send(badgeSvg);
});
});
app.get('/defaults.svg', function (req, res) {
var badgeConfig = {
badge: 'baseBadge',
text: ['Hello', 'World'],
color: {
left: '#555',
right: '#4c1',
font: '#fff',
shadow: '#010101'
},
font: {
fontFace: 'fonts/Open_Sans/OpenSans-Bold.ttf',
fontSize: 11
},
paddingX: 6,
paddingY: 6
};
openBadge(badgeConfig, function (err, badgeSvg) {
res.set('Content-Type', 'image/svg+xml');
res.send(badgeSvg);
});
});
app.get('/', function (req, res) {
res.send(
'<html>' +
'<head>' +
'<style>' +
' img {vertical-align: top} ' +
' * {line-height: 25px}' +
'</style>' +
'</head>' +
'<body style="font-family: monospace">' +
'Default Confg: <img src="defaults.svg"/><br>' +
'A Basic Badge: <img src="simple.svg"/><br>' +
'Changed Fonts: <img src="font.svg"/><br>' +
'Changed Color: <img src="colors.svg"/><br>' +
'</body>' +
'</html>'
)
});
app.listen(1337, function (err) {
console.log('Listening on http://localhost:1337/');
});