Skip to content

Instantly share code, notes, and snippets.

@skchronicles
Created April 21, 2020 14:24
Show Gist options
  • Save skchronicles/49665181da4f94435be613dca1057b2f to your computer and use it in GitHub Desktop.
Save skchronicles/49665181da4f94435be613dca1057b2f to your computer and use it in GitHub Desktop.
Bash one-liners: covert images to base64 and embed in HTML
# USAGE: image2html /path/to/images/*.png > out.html
function image2html(){
for f in $@; do b=$(cat "$f" | base64 -w 0); echo "<img src=\"data:image/${f##*.};base64,${b}\" alt=\"${f%.*}\">"; done
}
export -f image2html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment