Created
November 21, 2014 22:17
-
-
Save ryanj/e33185cdeef121863012 to your computer and use it in GitHub Desktop.
encode assets to be loaded inline as dataURIs
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 | |
function base64DataUri($sFile) | |
{ | |
// Switch to right MIME-type | |
$sExt = strtolower(substr(strrchr($sFile, '.'), 1)); | |
switch($sExt) | |
{ | |
case 'gif': | |
case 'jpg': | |
case 'png': | |
$sMimeType = 'image/'. $sExt; | |
break; | |
case 'ico': | |
$sMimeType = 'image/x-icon'; | |
break; | |
case 'eot': | |
$sMimeType = 'application/vnd.ms-fontobject'; | |
break; | |
case 'otf': | |
case 'ttf': | |
case 'woff': | |
$sMimeType = 'application/octet-stream'; | |
break; | |
default: | |
exit('Invalid extension file!'); | |
} | |
$sBase64 = base64_encode(file_get_contents($sFile)); | |
return "data:$sMimeType;base64,$sBase64"; | |
} | |
$file = 'static/font/overpass_bold-webfont.woff'; | |
print base64DataUri($file); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment