Skip to content

Instantly share code, notes, and snippets.

@willread
Last active December 17, 2015 00:49
Show Gist options
  • Save willread/5523843 to your computer and use it in GitHub Desktop.
Save willread/5523843 to your computer and use it in GitHub Desktop.
Outputs a css file containing a class declaration for each image file in the current folder, with the binary contents of those images base64 encoded as data urls as well as their width and height. Dots in filenames are replaced with underscores. Using the images is as simple as <img class="filename_extension">, where an image called "filename.ex…
for f in `ls | egrep "\.jpg|\.jpeg|\.gif|\.png$"`; do echo -e ".`echo $f | tr . "_"` {\n\twidth: `identify -format '%w' $f`px;\n\theight: `identify -format '%h' $f`px;\n\tbackground: url(data:image/${f#*.};base64,"; openssl base64 -in $f | tr -d "\n" | tr -d "\r"; echo -e ");\n}\n"; done > images.css
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment