We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
dataurl
1 parent 3a7ae53 commit 5d76fc2Copy full SHA for 5d76fc2
.functions
@@ -11,9 +11,13 @@ if [ $? -eq 0 ]; then
11
}
12
fi
13
14
-# Create a data URL from an image (works for other file types too, if you tweak the Content-Type afterwards)
15
-dataurl() {
16
- echo "data:image/${1##*.};base64,$(openssl base64 -in "$1")" | tr -d '\n'
+# Create a data URL from a file
+function dataurl() {
+ local mimeType=$(file --mime-type "$1" | cut -d ' ' -f2)
17
+ if [[ $mimeType == text/* ]]; then
18
+ mimeType="${mimeType};charset=utf-8"
19
+ fi
20
+ echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')"
21
22
23
# Start an HTTP server from a directory, optionally specifying the port
0 commit comments