Last active
February 11, 2016 11:39
-
-
Save aaferrari/a0fc51b784217ab5bf41 to your computer and use it in GitHub Desktop.
Conversor de archivos a "inline" en Bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
file2base64 () { | |
# Si es una archivo de internet, entonces se descarga temporalmente y luego se borra | |
if [[ "$1" =~ ^https?:// ]]; then | |
ubicacion="/tmp/imagen-temporal"; | |
wget -q -O $ubicacion $1; | |
echo 'data:'$(file --mime-type -b $ubicacion)";base64,"$(base64 -w0 $ubicacion); | |
rm -f $ubicacion > /dev/null; | |
else # De lo contrario se asume que es un archivo local | |
# Se utilizan los comandos file para obtener el tipo de archivo y base64 para codificarlo en ese formato | |
echo 'data:'$(file --mime-type -b "$1")";base64,"$(base64 -w0 "$1") | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment