Skip to content

Instantly share code, notes, and snippets.

@westc
Last active January 31, 2017 16:35
Show Gist options
  • Save westc/102515dee2c5320691e044886a2256f5 to your computer and use it in GitHub Desktop.
Save westc/102515dee2c5320691e044886a2256f5 to your computer and use it in GitHub Desktop.
Turn my CW logo into a PNG
(function(size) {
var data = '\
<svg xmlns="http://www.w3.org/2000/svg" height="' + size + '" width="' + size + '">\
<foreignObject width="100%" height="100%">\
<div xmlns="http://www.w3.org/1999/xhtml">\
<div style="position: absolute;\
margin: 0.2em;\
font-family: Tahoma;\
font-size: ' + (size * 100 / 260) + 'px;\
font-weight: bold;\
transform: rotate(345deg);\
color: #6CF;\
background-color: #036;\
text-align: center;\
border-radius: 2em;\
height: 2em;\
line-height: 2em;\
display: inline-block;\
width: 2em;\
padding: 0.1em;\
box-shadow: inset 0 0 1em #000, 0 0 0.05em 0.1em #FFF, 0 0 0.1em 0.1em #000;\
">CW</div>\
</div>\
</foreignObject>\
</svg>';
var img = new Image();
img.onload = function() {
console.clear();
var canvas = document.createElement('canvas');
canvas.style.height = 0;
canvas.height = size;
canvas.width = size;
document.body.appendChild(canvas);
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
console.clear();
console.log('Done ' + new Date);
location.href = canvas.toDataURL('image/png');
};
img.src = 'data:image/svg+xml;base64,' + window.btoa(data);
})(1024);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment