Skip to content

Instantly share code, notes, and snippets.

@vivi90 vivi90/php-badge-template forked from nebrelbug/template
Last active Sep 4, 2019

Embed
What would you like to do?
An SVG template for PHP which will render ReadMe badges
<?php
$leftWidth = strlen($leftText) * 10;
$rightWidth = strlen($rightText) * 13 + 5;
$totalWidth = $leftWidth + $rightWidth - 5;
?>
<svg xmlns="http://www.w3.org/2000/svg" width="<?= $totalWidth ?>" height="20">
<linearGradient id="smooth" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<mask id="round">
<rect width="<?= $totalWidth ?>" height="20" rx="4" fill="#fff"/>
</mask>
<g mask="url(#round)">
<rect width="<?= $leftWidth ?>" height="20" fill="<?= $leftBackgroundColor ?>"/>
<rect x="<?= $leftWidth ?>" width="<?= $rightWidth ?>" height="20" fill="<?= $rightBackgroundColor ?>"/>
<rect width="<?= $totalWidth ?>" height="20" fill="url(#smooth)"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="12">
<text x="<?= $leftWidth / 2 + 1 ?>" y="15" fill="#010101" fill-opacity=".3"><?= $leftText ?></text>
<text x="<?= $leftWidth / 2 + 1 ?>" y="14" fill="<?= $leftTextColor ?>"><?= $leftText ?></text>
<text x="<?= $leftWidth + $rightWidth / 2.5 - 1 ?>" y="15" fill="#010101" fill-opacity=".3"><?= $rightText ?></text>
<text x="<?= $leftWidth + $rightWidth / 2.5 - 1 ?>" y="14" fill="<?= $rightTextColor ?>"><?= $rightText ?></text>
</g>
</svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.