Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate a Bitcoin icon in SVG and PNG
<?php
ob_start();
$text = '&#x20bf;';
?><?xml version="1.0"?>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 128 128">
<defs>
<filter id="shadow" x="0" y="0" width="200%" height="200%">
<feGaussianBlur in="SourceAlpha" stdDeviation="8"/>
<feOffset dx="8" dy="8" result="offsetblur"/>
<feFlood flood-color="#000000" flood-opacity="1"/>
<feComposite in2="offsetblur" operator="in"/>
<feMerge>
<feMergeNode/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>
</defs>
<g filter="url(#shadow)">
<circle
fill="orange"
stroke="transparent"
cx="32"
cy="32"
r="31"
stroke-width="0">
</circle>
<text
transform="rotate(10 32 32)"
x="32"
y="32"
text-anchor="middle"
fill="white"
font-size="36pt"
stroke="0"
dy=".3em">
<?php echo $text; ?>
</text>
</g>
</svg>
<?php
$svg = ob_get_clean();
// write out the SVG to file
file_put_contents( 'bitcoin-icon.svg', $svg );
// now use Imagick to render the icon to raster
$im = new Imagick();
$im->setBackgroundColor( new ImagickPixel( 'transparent' ) );
$im->readImageBlob( $svg );
$im->setImageFormat( "png24" );
$im->writeImage( 'bitcoin-icon.png' );
$im->clear();
$im->destroy();
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.