mirror of
https://github.com/kastdeur/dotfiles.git
synced 2024-12-22 01:03:35 +01:00
Cool utility to base64 a file
This commit is contained in:
parent
13dc87abe2
commit
f5bf25dcf7
1 changed files with 18 additions and 0 deletions
18
bash/bash.d/network.bash
Normal file
18
bash/bash.d/network.bash
Normal file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
function data_url() {
|
||||
if [ -z "$1" ]; then
|
||||
cat << EndOfMessage
|
||||
Create a data URL that can be directly used in HTML.
|
||||
Usage: data_url <path_to_file>
|
||||
EndOfMessage
|
||||
return
|
||||
fi
|
||||
local mime_type base64
|
||||
mime_type=$(file -b --mime-type "$1")
|
||||
if [[ "$mime_type" == 'image/svg' ]]; then
|
||||
mime_type='image/svg+xml'
|
||||
fi
|
||||
base64=$(base64 "$1")
|
||||
echo "data:$mime_type;base64,$base64";
|
||||
}
|
Loading…
Reference in a new issue