Created
November 27, 2012 13:55
-
-
Save yarmand/4154322 to your computer and use it in GitHub Desktop.
Draw text on favicon
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
(function () { | |
var canvas = document.createElement('canvas'), | |
ctx, | |
img = document.createElement('img'), | |
link = document.getElementById('favicon').cloneNode(true), | |
day = (new Date).getDate() + ''; | |
if (canvas.getContext) { | |
canvas.height = canvas.width = 16; // set the size | |
ctx = canvas.getContext('2d'); | |
img.onload = function () { // once the image has loaded | |
ctx.drawImage(this, 0, 0); | |
ctx.font = 'bold 10px "helvetica", sans-serif'; | |
ctx.fillStyle = '#F0EEDD'; | |
if (day.length == 1) day = '0' + day; | |
ctx.fillText(day, 2, 12); | |
link.href = canvas.toDataURL('image/png'); | |
document.body.appendChild(link); | |
}; | |
img.src = 'ical-icon.png'; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment