Skip to content

Instantly share code, notes, and snippets.

@lesleh
Created January 15, 2015 12:25
Show Gist options
  • Select an option

  • Save lesleh/4fa071d07750df0997a8 to your computer and use it in GitHub Desktop.

Select an option

Save lesleh/4fa071d07750df0997a8 to your computer and use it in GitHub Desktop.
Bash script to create data URIs.
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "No filename specified." >&2
exit 1
fi
FILENAME=$1
MIMETYPE=$(file -b --mime-type "$FILENAME")
DATA=$(cat "$FILENAME" | base64)
echo "data:${MIMETYPE};base64,${DATA}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment