Name
Badge::Simple - Generate simple SVG badges
Synopsis
use Badge::Simple qw/badge/;
badge( left => "Hello", right => "World!", color => "yellow" )
->toFile( "hello.svg" );
Description
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:
left
-
Text on the left side of the badge. Required.
right
-
Text on the right side of the badge. Required.
color
-
Either an HTML hex color string (
"#AABBCC"
), or one of the following predefined color schemes:blue
,brightgreen
,green
,lightgrey
,orange
,red
,yellow
,yellowgreen
. If omitted, defaults tolightgrey
. font
-
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.
To write the SVG to a file, use the ->toFile($filename)
method on the return value of the badge
function, or ->toFile($filename, 1)
to nicely indent the XML. To get the SVG as a string, use the ->toString()
method, or ->toString(1)
for indented XML.
Samples
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' )
→
See Also
https://github.com/badges/shields
Author, Copyright, and License
Copyright (c) 2018 Hauke Daempfling (haukex@zero-g.net).
This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.
For more information see the Perl Artistic License, which should have been distributed with your copy of Perl. Try the command perldoc perlartistic
or see http://perldoc.perl.org/perlartistic.html.
Please see the file README.md in the module's distribution for additional information.