Skip to content

Instantly share code, notes, and snippets.

@cristiklein
Created September 9, 2023 21:13
Show Gist options
  • Save cristiklein/b16301c402128027195a15ea1c0b0d02 to your computer and use it in GitHub Desktop.
Save cristiklein/b16301c402128027195a15ea1c0b0d02 to your computer and use it in GitHub Desktop.
Convert any file into a data: URI
#!/bin/sh
if [ $# -ne 1 ]; then
echo "Usage: $0 FILENAME"
exit 1
fi
mimetype=$(file -bN --mime-type "$1")
content=$(base64 -w0 < "$1")
echo "url('data:$mimetype;base64,$content')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment