-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.data.uris.php
executable file
·46 lines (40 loc) · 1017 Bytes
/
make.data.uris.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/php
<?php
# This is a PHP script for making CSS with fonts embedded in Data URIs
# Example usage:
#
# ./make.data.uris.php Caulixtla008.woff2 Caulixtla > Caulixtla.css
#
# Donated to the public domain (CC0) by Sam Trenholme June 3 2018
# Parse args
if($argc != 3 && $argc != 4) {
print "Usage: " . $argv[0] . " {WOFF(2) font file} {font name}\n";
exit(0);
}
# Load and base64 convert font file
$a = file_get_contents($argv[1]);
$b = base64_encode($a);
# See if this is a bold or italic font
$more = "";
if($argc == 4) {
if(preg_match('/B/',$argv[3])) {
$more = "font-weight: bold";
} else {
$more = "font-style: italic";
}
}
# Determine MIME type
$type = "application/x-font-woff";
if(preg_match('/woff2$/',$argv[1])) {
$type = "application/font-woff2";
}
# Output CSS
print "@font-face {\n";
print "\tfont-family: " . $argv[2] . ";\n";
print "\tsrc:url(data:" . $type . ";base64," . $b .
") format('woff');\n";
if($more) {
print "\t" . $more . ";\n";
}
print "}\n";
?>