Permalink
Browse files

.functions: Add `dataurl` function

  • Loading branch information...
1 parent 1c94b9b commit 36666d6b7214ef4537ed336ac6513ea80c15aa70 @mathiasbynens committed Mar 22, 2012
Showing with 5 additions and 0 deletions.
  1. +5 −0 .functions
View
@@ -3,6 +3,11 @@ function md() {
mkdir -p "$@" && cd "$@"
}
+# Create a data URL from an image (works for other file types too, if you tweak the Content-Type afterwards)
+dataurl() {
+ echo "data:image/${1##*.};base64,$(openssl base64 -in "$1")" | tr -d '\n'
+}
+
# Start an HTTP server from a directory, optionally specifying the port
function server() {
local port="${1:-8000}"

3 comments on commit 36666d6

Is it better to no using openssl to allow it works in cygwin?

echo "data:image/${1##*.};base64,$(base64 -i "$1")" | tr -d '\n'
Owner

mathiasbynens replied Mar 22, 2012

base64 is not available by default on all Linux versions, so I prefer to use openssl here. I work on Linux more often than on Windows, sorry!

Oh, it's available on my ubuntu. I thought it was default included yet.

Please sign in to comment.