Skip to content

Instantly share code, notes, and snippets.

@jonlabelle
Last active June 18, 2016 18:17
Show Gist options
  • Save jonlabelle/7091476 to your computer and use it in GitHub Desktop.
Save jonlabelle/7091476 to your computer and use it in GitHub Desktop.
Bash function that creates a data URI scheme for a file.
#!/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