Skip to content

Instantly share code, notes, and snippets.

@xero
Created June 5, 2013 16:04
Show Gist options
  • Save xero/5715083 to your computer and use it in GitHub Desktop.
Save xero/5715083 to your computer and use it in GitHub Desktop.
an example of base64 encoding fonts for use on the web. this is just a POC, your base64 encoded data should be cached and saved on the server, not generated at run/request time. so i suppose this is more of a syntax/workflow example.
<html>
<head>
<title>base64 encoded webfonts example</title>
<?php
$file = "webfont.eot";
$handle = fopen($filename, "r");
$data = fread(fopen($file, "r"), filesize($file));
?>
<style>
@font-face {
font-family: 'webfont';
src: url('webfont.eot?#iefix') format('embedded-opentype'),
url('webfont.woff') format('woff'),
url('webfont.ttf') format('truetype'),
url('webfont.svg#svgFontName') format('svg');
}
@font-face {
font-family: 'webfont';
src: url(data:application/font-woff;charset=utf-8;base64,<? echo base64_encode($data); ?>) format('woff'),
url('webfont.ttf') format('truetype');
}
body {
font-family: 'webfont';
}
</style>
</head>
<body>
<h1>hello base64 encoded webfonts!</h1>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment