A base64 encoder for images that optionally embeds encoded image data in HTML, Markdown, CSS, LESS, or SASS files at the site of a {{64}} tag.
Documentation Site
Dependencies
Requires Python 2 or 3
Tested in versions 2.7.x and 3.3.x
Install
If you use pip for Python package management, you can install Six-Four with the following command:
pip install sixfour
Otherwise, obtain the source code with one of the following methods:
Method 1: Clone the sixfour repository with the following command:
git clone https://github.com/chrissimpkins/six-four.git
Method 2: Download a compressed archive with one of the following links:
Then, navigate to the top level of the source directory and run the following command:
python setup.py install
Usage
base64 Encoding --> Standard Output Stream
Include the -i
flag with the input image file path and the raw base64 encoded image data will be printed to the standard output stream:
sixfour -i 'path/to/image.png'
You can pipe the raw base64 encoded image data to any other application:
sixfour -i 'path/to/image.png' | coolimageapp --process-it
base64 Encoding --> <img> Tag in HTML or Markdown file
Insert the tag {{64}}
at the site in your Markdown or HTML file where you want to embed the base64 encoded image tag:
<!DOCTYPE html>
...snip...
<body>
<div class="main-container">
<div class="main wrapper clearfix">
{{64}}
</div> <!-- #main -->
</div> <!-- #main-container -->
...snip...
</body>
</html>
Include both the -i
flag with an image file path and the -o
flag with a HTML or Markdown file path in your command:
sixfour -i 'path/to/coolimage.png' -o 'path/to/index.html'
The {{64}}
tag in the HTML above will be replaced with a <img> tag that looks like this:
<!DOCTYPE html>
...snip...
<body>
<div class="main-container">
<div class="main wrapper clearfix">
<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAJYAAAAdCAQAAADif11yAAAMs0lEQVR4XuXVeXRUZZ7G8e/73ltb
KiQEEnayYwSSEBYBaQF3BxVQoBFBcMGIGEG7e9C2tdumjyAoR3oUURAUQURAwKUH2nYJCOg0QpBF
CYuGxUQIS4AklVTVvfc3Wid1kkAPYjMe//Dz/vfc+9aTPOfUKSVDWMkvQf3/OZRV9khpaT6P7YzH
0i/hcgrkmLEQG4Cu9vTT1zgA6OMJt/H36G39C5kKVhK1Aqd9Uko2IeyUzpk9cdY6mf1S0nEA8F0/
rEevXHLIJZfs+Lz4+tsmv0T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GL7594YGhgqpsuhag9mtlKWpi/nv+Vfd36AaA4iyi
znpied5VCLvHjl44evE3NwrqhOc9gk6hwmBP22GL819eNSyEIsr5StmKgP+dV64uSO36/zbWXZWe
mUpgb/b7DxR3EnSF+2lsgLFl7qMKhW//pOMAvl0KhYGzCQcASZ/nKtJU6Q1DNgyu0RrXjFVfRfJX
3Js01XrjTetvDmiN8czKPQB//txdqID9nQ8+xwwU2LZC4VgAji0oIBwCCIcjT7QdBuTiua7tmkpj
47CNA2uUxnh6WQn4l6pjCostvT4YedTbBHAMKwwwusi9LtKUfWCWazqK82RTz1FnjQVFc/0Frr2m
bWDWuD9qctPWjUQMqgo+xVbZEpyFBeBfyxzZ7ixP/Ad1Xj/W6hbfcuOoC1M8B2IeefApIhZXJI3w
LTXKI/lB/2MjphLRKWTcb7yvq12oMnMegnX6VT6TT4LLAN6ucubINvtv32wApHSVfMyO2nkJJQAL
y1sP964wjrkwHc9+/0MjZgCs39PsTmOXKWbQtWnoX3stsIqC8w/uARgQ9N1nfGh831Sq5yM0pqjj
iLZp4NsjQlTlMYJESYNzU9N7ehVcNSpHTGmUd3Z3djdMUr3CGUdf276gX36fguZn5+O+y+9JFNUw
/7M5uNPdfQe1iSbdXTTozPQQfZtfG+18jZsGJo/vP+7Sxk2/js/vMzLvFa9EPqtx09DOd/cd0lo4
45hxa6JB3PvS6E6/9uaRaF3739TnSviluvOabYsDSYKxq9WtH22jIdV3/InpdiwS+0Hf4TNPUkcz
hF+GIUQNJeKVvVvWb+Xz0JerP9pPY7J+0+c7Pmfrqc1rZlbX3/5fbmn4nw/pQsUAAAAASUVORK5C
YII=" alt='coolimage' />
</div> <!-- #main -->
</div> <!-- #main-container -->
...snip...
</body>
</html>
The image filename is used as the <alt>
attribute in the tag. The image MIME type is automatically inserted in the data URI based upon your image file extension.
base64 Encoding --> Embedded Data URI in CSS File
Insert the tag {{64}}
at the site in your CSS file where you want to embed the base64 encoded image data URI:
.base64test {
background: #fff {{64}} repeat-x;
}
Include both the -i
flag with an image file path and the -c
(or --css=) flag with a CSS file path in your command:
sixfour -i 'path/to/coolimage.png' -c 'path/to/main.css'
And your CSS file will look like this:
.base64test {
background: #fff url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAIAAABLixI0AAAAOElEQVQ4y2N4Qz3AAMSfP73DJCEIPxuNZBh112Bz14cPEISPjdVdg9Ws0fAaDa8hHF6j5dcQcxcA3DHODs/IAR8AAAAASUVORK5CYII=') repeat-x;
}
base64 Encoding --> Embedded Data URI in LESS File
Use the -l or --less flag with a path to the LESS file. Insert the LESS variable @sixfour at the site where you would like to embed your base64 encoded image. This variable does not need to be defined in your LESS file.
.funky {
background: #fff @sixfour repeat-x;
font: 2px/3px {
family: fantasy;
size: 30em;
weight: bold;
}
}
Run Six-Four on your LESS file (before you compile it with LESS) with the following syntax:
sixfour -i 'path/to/coolimage.png' --less='less/main.less'
base64 Encoding --> Embedded Data URI in SASS File
If you use the -s or --sass flag with the file path to a SASS file, you can use the SASS variable $sixfour at the replacement site for your data URI. You do not need to define this variable in your SASS file, simply insert it where you would like the data URI to be embedded.
.funky {
background: #fff $sixfour repeat-x;
font: 2px/3px {
family: fantasy;
size: 30em;
weight: bold;
}
}
Then run Six-Four on your SASS file (before your compile it with SASS or Compass) using the following syntax:
sixfour -i 'path/to/coolimage.png' --sass='sass/main.scss'
and compile the file normally with sass:
sass --update 'sass/main.scss'
Help
Help documentation is accessed with either of the following commands:
sixfour -h
or
sixfour --help
License
MIT license
Changelog
v.1.3.3 - added Python wheel to the release
v1.3.1 - updated documentation + updated tests for Python v 2.7.6
v1.3.0 - added LESS file embed support
v1.2.0 - added SASS file embed support + bug fixes for CSS embed + automatic MIME type detection for jpg, gif, png, and svg file types
v1.1.3 - modified Python 3 vs 2 interpreter check
v1.1.2 - updated -h flag help documentation
v1.1.0 - added Python 3 support with Python 2 + 3 tests
v1.0.1 - added alt attribute completion with image filename
v1.0.0 - initial release
✪ Chris