Skip to content

A poor man (but fully functional) Base64 files encoder

License

Notifications You must be signed in to change notification settings

IU5HKU/BASE64Enc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

BASE64Enc

A poor man (but fully functional) Base64 files encoder in plain C, compile with every compiler you want.

When i was developing MiniWX i've faced to a choice, how to embed icons in html page buttons? Well, digging around for a solution i've learned that for simple icons and tiny images you can recur to base64 encoding method. It's not a compression method, instead the size becomes 1/3 bigger than the files you are attempting to convert, because 3 bytes (24bit) are divided in 4 six-bits values, and each values is associated to a char. In this way the raw data becoms text data, and browsers can decode it and show your icon or tile or whatever graphics file you have encoded. It's fast and easy, the overhead is tolerable if you are using small graphics images, in IoT you have only to serve the page and forget about handle other request from the client, everything is in the file... and 'cmon, everyone likes a fancy icon in their buttons, isn't it? :-) Wrote this as an exercise in five minutes after finding the algo on wikibooks, you could write a gui drag'n'drop app, but there is plenty of webpages who offers this service for free, so after understanding the concept there's no need to reinvent the whell everytime.

This program generate a file .html where you can find a tag of type

  <img src='data:image/png;base64,iVBOR.....QmCC'\>

i've left "png" but can be used for others graphicals files actually, because with this encoding the whole file is encoded, headers, datas, everything, and reconstructed client side by the browser as in origin. You can embed the resultan icon in a button like this:

<button name='exit' onclick='history.back()'><img src='data:image/png;base64,iVBOR..........................na4GvRKi7IA1NnPfvvAErgd32GJtwDAAAAAElFTkSuQmCC'/> Exit</button>

and with the proper style to center image and text in the button, this will be the result:

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" lang="en">
    <title>Embedded Base64 icon</title>
  </head>
  <style>
    button { repeat-x center;}
  </style>
<body>
  <button name='exit'><img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAIGNIUk0AAIcbAACL/wAA/bEAAINJAAB9LgAA7W0AADg+AAAkPqJQ9KgAAAchSURBVHjaXJVrjF1VFcd/a+99z7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Mn9O39c5L5n/58g7d0VLFQwrU3XL6ZG7HV8PYtZ/411qZf2bXkWfPv2X539o+Pufe0UPjt9eOp4tPWo+LlJz1OBF8gFbmIURUTI6KLe3qofqLy+a/8Pza8i1NaIssJGcXLKoa7Z9OkiPxCP1RD3uSLnMwEmkHf+xEqzdXDzcOpK0HP53yhalMfZIGYid0F4nanfznL++e/sFYYem2DWZ0anLV5/na4GvRKi7IA1NnPfvvAErgd32GJtwDAAAAAElFTkSuQmCC'/> Exit</button>
</body>

About

A poor man (but fully functional) Base64 files encoder

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages