Skip to content

Instantly share code, notes, and snippets.

@jaikdean
Last active December 14, 2015 21:29
Show Gist options
  • Save jaikdean/5151877 to your computer and use it in GitHub Desktop.
Save jaikdean/5151877 to your computer and use it in GitHub Desktop.
Bash script to base64 encode the given file and output a CSS background-image declaration
#!/bin/bash
base64=`openssl base64 -in $1`
mime=`file -b --mime-type $1`
echo "background-image: url(data:${mime};base64,${base64});" | tr -d '\n'

Usage

In a terminal, run ./base64enc.sh /path/to/file.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment