This is a php library that creates badges like and
and
,
according to Shields specification.
This library is used by https://poser.pugx.org
- PHP 8.1 or higher
- GD extension
you can still use the library with lower PHP versions, using the old releases
composer create-project badges/poser
ln -s poser/bin/poser /usr/local/bin/poserCreate an image
poser license MIT blue -p "license.svg"Flush an image
poser license MIT blueChoose a different style
poser license MIT blue -s "for-the-badge"The available styles are plastic, flat, flat-square, for-the-badge, and social.
You can also use the provided Docker Compose services:
docker compose run --rm php82 bin/poser license MIT blue
docker compose run --rm php83 bin/poser license MIT blue -p "license.svg"
docker compose run --rm php83 bin/poser license MIT blue -s "plastic" -p "license-plastic.svg"composer require badges/poseruse PUGX\Poser\Render\SvgPlasticRender;
use PUGX\Poser\Poser;
$render = new SvgPlasticRender();
$poser = new Poser([$render]);
echo $poser->generate('license', 'MIT', '428F7E', 'plastic');
// or
echo $poser->generateFromURI('license-MIT-428F7E.svg?style=plastic');
// or
echo $poser->generateFromURI('license-MIT-428F7E?style=plastic');
// or
$image = $poser->generate('license', 'MIT', '428F7E', 'plastic');
echo $image->getStyle();The allowed styles are: plastic, flat, flat-square, for-the-badge, and social.
Badges generated from a URI support these query string options:
| Option | Description |
|---|---|
style |
Badge style: plastic, flat, flat-square, for-the-badge, or social. |
labelColor |
Color for the left side of the badge. Accepts named colors, 6-digit hex, or 3-digit hex. |
logo |
Optional logo as an image URL, data:image/... URI, or SVG path data. |
logoColor |
Color used when logo is SVG path data. Defaults to white. Accepts named colors, 6-digit hex, or 3-digit hex. |
Examples:
echo $poser->generateFromURI('license-MIT-blue.svg?style=social');
echo $poser->generateFromURI('build-passing-brightgreen.svg?labelColor=555');
echo $poser->generateFromURI('github-stars-333.svg?style=social&logo=https%3A%2F%2Fexample.com%2Fgithub.svg');
$logo = rawurlencode('M12 2L2 22h20L12 2z');
echo $poser->generateFromURI('php-8.4-777.svg?logoColor=blueviolet&logo=' . $logo);When these options are used in a URL, encode reserved characters. In particular, encode # as %23, and encode full image/data URLs passed as logo.
The CLI currently exposes style selection with --style; labelColor, logo, and logoColor are available through URI-based generation.
Since v3.4.0, SVG templates use vendorStartX and valueStartX instead of the old vendorStartPosition and valueStartPosition placeholders. If you maintain custom templates, update them before upgrading:
- {{ vendorStartPosition }}
- {{ valueStartPosition }}
+ {{ vendorStartX }}
+ {{ valueStartX }}These values are the text center positions multiplied by 10 and are intended to be used with transform="scale(.1)", as the bundled templates do.
The renderer also provides these optional template placeholders: vendorUpper, valueUpper, vendorTextLength, valueTextLength, vendorWidthMinus1, valueWidthMinus1, valueRectX, separatorX, and logoElement.
Dashes -- → - Dash
Underscores __ → _ Underscore
_ or Space → Space
For more info please see the behat features and the examples in the php-spec folder
Not only because all the other languages already have it, but having the latest stable release in the readme could save time.
Active contribution and patches are very welcome.
Please refer to CONTRIBUTING
You can use the env var CONTAINER to run the tests in a specific PHP version. The default version if CONTAINER is omitted is php83.
CONTAINER=php83 make setupCONTAINER=php83 make testsmake matrix-tests