Badge::Simple - Generate simple SVG badges
use Badge::Simple qw/badge/; badge( left => "Hello", right => "World!", color => "yellow" ) ->toFile( "hello.svg" );
This module generates simple badges, based heavily on the default "flat" style of Shields.io.
The module currently exports a single function,
badge, which returns an XML::LibXML::Document object representing the SVG file. The function takes the following arguments:
Text on the left side of the badge. Required.
Text on the right side of the badge. Required.
Either an HTML hex color string (
"#AABBCC"), or one of the following predefined color schemes:
yellowgreen. If omitted, defaults to
The filename of a font file (as supported by Imager::Font), for example you might point this at your local copy of Verdana.ttf. This font is currently only used to calculate the width of the badge. If omitted, defaults to DejaVuSans.ttf, which is distributed with this module.
Note: Different font libraries may calculate the widths of fonts slightly differently. This module's tests check to make sure that these variations are not too large (within a couple of pixels), but be aware that badges generated on different systems might have slightly different widths.
The return value of
badge, an XML::LibXML::Document object, can easily be used in one of the following ways (
$svg is the return value):
Write to a file:
Save to a string:
my $string = $svg->toString();
Write to a file with the XML nicely indented:
Save to a string with the XML nicely indented:
my $string = $svg->toString(1);
The following samples should be visible if you are viewing an HTML version of this documentation and you have an Internet connection available. Otherwise, please see the sample images in the t/ directory of the module distribution.
badge( left => "Hello", right => "World!", color => "yellow" ) →
badge( left=>'CPAN Testers', right=>'100%', color=>'brightgreen' ) →
badge( left=>'foo', right=>'bar', color=>'#e542f4' ) →
Copyright (c) 2018 Hauke Daempfling (firstname.lastname@example.org).
This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.
Please see the file README.md in the module's distribution for additional information.