Last active
June 18, 2016 18:17
-
-
Save jonlabelle/7091476 to your computer and use it in GitHub Desktop.
Bash function that creates a data URI scheme for a file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# generate data uri scheme for file | |
function datauri() | |
{ | |
local mimeType=$(file -b --mime-type "$1") | |
if [[ $mimeType == text/* ]]; then | |
mimeType="${mimeType};charset=utf-8" | |
fi | |
echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment