How to convert/encode fonts into base 64 format?

4.3k Views Asked by At

As there are several issues related to fonts so it is best to convert it keep it in base 64 format. Sometimes sites like fontsquirrel.com etc. are not able to convert your fonts in base64 format showing issues like fonts are blacklisted or other issues. So how to convert fonts into base64 format in that case (in case we have no such legal issues with fonts)

1

There are 1 best solutions below

1
paraS elixiR On

I just found a solution to encode fonts in base64 format using command prompt.

  1. open command prompt / terminal
  2. go to the folder where the font files are.
  3. Type in following command

base64 name-of-thefont-file-name.woff

(I prefer to use .woff as it works with several advance browsers)

In case you are having difficulty in copying it from command prompt /terminal - you can redirect output to a file

base64 name-of-thefont-file-name.woff > base64encoded.txt

If one needs encoded font in just one line use following command

base64 -w 0 name-of-thefont-file-name.woff > base64encoded.txt

Now use this encoded code in css file using following code snippet -

@font-face { font-family: "Font Name"; src:url(data:font/woff;charset=utf-8;base64,font-file-in-encoded-form) format('woff'); font-weight: normal; font-style: normal; }