Name
Badge::Simple - Generate simple SVG badges
Synopsis
use Badge::Simple qw/badge/;
badge( left => "Hello", right => "World!", color => "yellow" )
->toFile( "hello.svg" );
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.
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:
$svg->toFile($filename);
Save to a string:
my $string = $svg->toString();
Write to a file with the XML nicely indented:
$svg->toFile($filename, 1);
Save to a string with the XML nicely indented:
my $string = $svg->toString(1);
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.