https://github.com/nickssilver/base64-image-encoder
Base64 image encoder written in C
https://github.com/nickssilver/base64-image-encoder
c encoder-decoder
Last synced: 6 months ago
JSON representation
Base64 image encoder written in C
- Host: GitHub
- URL: https://github.com/nickssilver/base64-image-encoder
- Owner: nickssilver
- Created: 2022-09-08T13:44:32.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-25T19:23:29.000Z (over 3 years ago)
- Last Synced: 2025-03-15T13:11:33.110Z (10 months ago)
- Topics: c, encoder-decoder
- Language: C
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#
base64-image-encoder:monocle_face:
Base64 image encoder written in C.
## Repo Description
Base64 is an encoding algorithm that converts any characters, binary data, and even images or sound files into a readable string, which can be saved or transported over the network without data loss. The characters generated from Base64 encoding consist of Latin letters, digits, plus, and slash. Base64 is most commonly used as a `MIME` (Multipurpose Internet Mail Extensions) transfer encoding for email.
Base64 images are primarily used to embed image data within other formats like HTML, CSS, or JSON. By including image data within an HTML document, the browser doesn't need to make an additional web request to fetch the file, since the image is already embedded in the HTML document. A Base64 representation of an image is larger than a separate image and the string gets very long for large images. You should primarily use Base64 for small images and always test both embedded and external images to see what works best.
Once converted to Base64, encoded image data will look similar to this (shortened for simplicity):
```
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgwnLpRPAAA...
```
The string can be used instead of an URL in the src attribute of the img element in HTML:
```
```
Or you can insert the string as a background-image in CSS:
```
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALQAAAC0CAYAAAA9zQYyAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzA...");
```
Other file types like XML and JSON also supports Base64 encoded images. Start by uploading an image file above and play with the different possibilities.
## Assumptions
You are building and running this application on a Debian-based Linux machine. Other distros and operating systems may have varied results.
## Dependencies and prerequisites
Have libcurl package installed. To install:
`$ sudo apt-get install libcurl4-openssl-dev`
Download and extract the libcurl library in the same location where you will clone the github repository
[Download](https://curl.se/download.html)
## Installing the application locally
Clone the repository:
`$ git clone https://github.com/nickssilver/base64-image-encoder.git`
In the root directory of the repository, set the `LD_LIBRARY_PATH` environment variable to the current directory:
`$ export LD_LIBRARY_PATH=$(pwd)`
Create the object file:
`$ gcc -c -Wall -Werror -fpic libencode.c`
Create a shared library from the object file:
`$ gcc -shared -o libencode.so libencode.o`
## Running the application locally
Compile the executable:
`$ gcc -L$(pwd) -Wall -o encode main.c -lencode -lcurl`
Move empty file to write into root directory, or create it:
`$ touch filename`
Run the executable with an image link and file name:
`$ ./encode https://www.image.png filename`
# Author:
- *Nicholas M. Gitobu* - [@nickssilver](https://github.com/nickssilver)