add data_url fn
This commit is contained in:
parent
5ebe8b934b
commit
3b6ea22add
1 changed files with 19 additions and 0 deletions
19
zsh/std.zsh
19
zsh/std.zsh
|
@ -5,3 +5,22 @@ function skip() {
|
||||||
shift
|
shift
|
||||||
tail -n +"$((n+1))" "$@"
|
tail -n +"$((n+1))" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# usage: data_url <file>
|
||||||
|
# turn file into a data url
|
||||||
|
data_url() {
|
||||||
|
if [ $# -eq 1 ]; then
|
||||||
|
file_path=$1
|
||||||
|
if [ -f "$file_path" ]; then
|
||||||
|
base64_data=$(base64 < "$file_path")
|
||||||
|
mime_type=$(file --mime-type -b "$file_path")
|
||||||
|
data_url="data:$mime_type;base64,$base64_data"
|
||||||
|
echo "$data_url"
|
||||||
|
else
|
||||||
|
echo "File not found: $file_path"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "\$ data_url [FILE_PATH]"
|
||||||
|
echo "Turn data into a data URL"
|
||||||
|
fi
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue