Last active
August 30, 2018 22:40
-
-
Save alex-georgiou/fa311a92184859dd33f5055a93adbca2 to your computer and use it in GitHub Desktop.
Generate a Bitcoin icon in SVG and PNG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ob_start(); | |
$text = '₿'; | |
?><?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