Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I convert embedded base64 encode font to a font file?

Tags:

I have an @font-face rule, and its look like this:

@font-face{     font-family:'F'; src:url("") format("embedded-opentype"), url(data:application/x-font-woff;charset=utf-8;base64,d09GRgABAA ... ETC... ETC 

Can i convert this to a font file?

Thanks!

like image 320
mauriblint Avatar asked Sep 21 '12 13:09

mauriblint


People also ask

Can you Base64 encode a file?

Base64 encoding uses printable characters to encode binary data. This enables another interesting use case: You can encode multiline files into Base64 strings.

What is Base64 font?

Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.

How do I encode a font to Base64?

Encode and view TTF to base64 online Encode TTF to base64 in a simple way. Get the text string of the font to your view. Save the result as an image or copy and past the text string where you need it to. Integrate the functionality to your product.

What is UTF 8 and Base64?

UTF-8 is like the other UTF encodings a character encoding to encode characters of the Unicode character set UCS. Base64 is an encoding to represent any byte sequence by a sequence of printable characters (i.e. A – Z , a – z , 0 – 9 , + , and / ). There is no System.


2 Answers

Copy the base64 encoded part and convert it. There are many ways to do that.

Linux

base64 -d base64_encoded_font.txt > font.woff 

Mac OS X

openssl base64 -d -in base64_encoded_font.txt -out font.woff 

WIndows

Go to http://www.motobit.com/util/base64-decoder-encoder.asp and paste the text. Choose "decode the data from a Base64 string (base64 decoding)" and "export to a binary file".

like image 60
mcrumley Avatar answered Oct 05 '22 23:10

mcrumley


@mcrumley's answer is correct, but for those of you who can't figure it out and/or are afraid of the command-line, I have an alternate method.

I just Googled your question, and found http://base64converter.com/ which can convert/decode (and encode) any base64 file back to its original format. I'd used it to encode and decode base64 images in this past, but this was my first attempt with a font. As a test I plugged in the embedded base64 font info I found in a random webpage's css file. You don't want the entire entry, leave off the css info or the conversion will fail.

  1. (For example) delete this info preceding the base64:

    @font-face{font-family:"Example";src:url(data:application/x-font-woff;base64, 
  2. Delete this from the end:

    ;font-weight:400;font-style:normal} 
  3. You'll be left with the base64 encoded data, paste that in the "Input" field, select "Decode" for the output and press the button. It will create a file called download.bin : click it to download it. Then change the file extension from bin to woff (your font file-type might be different, but it will say in the css). I was able to open the .woff file and the conversion worked perfectly; not only were all the outlines saved, but so were the glyph names, the opentype features, kerning, and everything.

Of course, like any method used to rip webfonts, the number of glyphs outputted will likely be limited to those used on the page in question.

If woff files aren't what you need, there are plenty of online tools to convert woff to the format of your choice. Or if you need an offline tool, check out this question I asked and the answers I received:

Modify Python Script to Batch Convert all "WOFF" Files in Directory

like image 21
Moscarda Avatar answered Oct 05 '22 23:10

Moscarda