Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Created May 27, 2012 05:46
Show Gist options
  • Save nicerobot/2802306 to your computer and use it in GitHub Desktop.
Save nicerobot/2802306 to your computer and use it in GitHub Desktop.
Convert references to image files into data URIs
#!/bin/sh
# Assumes pngs are in images/ under ./*.css
# Edits the files in-place. Make backups.
CSSD=${1:-${CSSD:-.}}
for c in $(ls ${CSSD}/*.css 2>/dev/null); do
for i in ${CSSD}/images/*.png; do
p=$(basename $i)
b="$(base64 ${i})"
perl -pi -e "s|images/${p}|data:image/png;base64,${b}|" ${c}
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment