Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

.functions: Add `dataurl` function

  • Loading branch information...
commit 36666d6b7214ef4537ed336ac6513ea80c15aa70 1 parent 1c94b9b
@mathiasbynens authored
Showing with 5 additions and 0 deletions.
  1. +5 −0 .functions
View
5 .functions
@@ -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

@yangg

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

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

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!

@yangg

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

Please sign in to comment.
Something went wrong with that request. Please try again.