Last active
August 29, 2015 14:14
-
-
Save thornbill/7e49ddee074bcd969328 to your computer and use it in GitHub Desktop.
Convert a jpg, png or gif to a data-uri
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 | |
for file; | |
do | |
echo -e "\033[0;32m>> $file\033[0m" | |
if [ -e $file ]; then | |
_ext=${file##*.} | |
if [[ "gif png jpg jpeg" =~ $_ext ]]; then | |
if [ $_ext == "jpg" ]; then _ext="jpeg"; fi | |
php -r "echo(\"data:image/$_ext;base64,\".base64_encode(file_get_contents(\"$file\")).\"\\n\");" | |
else | |
echo -e "\033[0;31mInvalid filetype [.$_ext]\033[0m" | |
fi | |
else | |
echo -e "\033[0;31mFile not found\033[0m" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage