Posts

Showing posts with the label Base64

Converting And Rendering Web Fonts To Base64 - Keep Original Look

Answer : In the Font Squirrel Expert options, make sure to set the 'TrueType Hinting' option to 'Keep Existing'. Either of the other options will cause the TrueType instructions (hints) to be modified, which will in turn affect the rendering of the font. Alternatively , if you're happy with the rendering of the font directly from GWF, you can just take that file and do the base64 encoding yourself. In OS X or Linux, use the built-in base64 command in Terminal/shell: $ base64 myfont.ttf > fontbase64.txt For Windows, you'll need to download a program to encode in base64 (there are several free/Open Source tools available). Copy the contents of that file, then use in your CSS as: @font-face { font-family: 'myfont'; src: url(data:font/truetype;charset=utf-8;base64,<<copied base64 string>>) format('truetype'); font-weight: normal; font-style: normal; } (Note that you may need to make some adjustments to the various @f...

Converting Hex To Base64 With Notepad++

Answer : The trick was that by converting the HEX directly in notepad++, It's taken as a ASCII value not as A HEX Value as intended. So we need to converted first the HEX --> ASCII then ASCII --> BASE64 1/ Select the string 2/ Using Notepad++ menu: Plugins -> Converter -> HEX -> ASCII 3/ Plugins -> MIME Tools -> Base64 Encode and we get the needed value The characters FB can be encoded as the 16-bit values 46004200 and encoding that in Base 64 gives RkI= . Using Notepad++ menu => TextFx => TextFx Tools => Base 64 decode : Converting +w== gives the single byte xFB . It show as thouse three characters in white on a black background. The status bar at the bottom of the window shows the buffer has a length of 1 (i.e. one). Converting RkI= gives the two characters FB . Shown in black on a white background, i.e. as normal text. The buffer is shown to have a length of 2. Conclusion, your initial conversion was of the two charactgers FB not the byt...

Creating A BLOB From A Base64 String In JavaScript

Answer : The atob function will decode a Base64-encoded string into a new string with a character for each byte of the binary data. const byteCharacters = atob(b64Data); Each character's code point (charCode) will be the value of the byte. We can create an array of byte values by applying this using the .charCodeAt method for each character in the string. const byteNumbers = new Array(byteCharacters.length); for (let i = 0; i < byteCharacters.length; i++) { byteNumbers[i] = byteCharacters.charCodeAt(i); } You can convert this array of byte values into a real typed byte array by passing it to the Uint8Array constructor. const byteArray = new Uint8Array(byteNumbers); This in turn can be converted to a BLOB by wrapping it in an array and passing it to the Blob constructor. const blob = new Blob([byteArray], {type: contentType}); The code above works. However the performance can be improved a little by processing the byteCharacters in smaller slices, rather than all at o...