Created
September 20, 2011 02:32
-
-
Save st44100/1228172 to your computer and use it in GitHub Desktop.
Base64 encoding sh for PNG,GIF image.
This file contains hidden or 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/sh | |
HEADER_STR="" | |
if [ $# -eq 0 ] ; then | |
echo "usage: ${0} [IMAGE_FILE_PATH]..." | |
exit 1 | |
fi | |
for I in $@ ; do | |
HEADER_STR=`/usr/bin/file -bI ${I} | /usr/bin/sed "s# .*##g"` | |
if [ "${HEADER_STR}" != "image/png;" -a "${HEADER_STR}" != "image/gif;" ] ; then | |
echo "${I} : NOT PNG or GIF file" | |
continue | |
fi | |
HEADER_STR="data:"${HEADER_STR}"base64," | |
echo "${HEADER_STR}" > ${I}_base64_tmp | |
/bin/cat ${I} | /usr/bin/openssl enc -base64 >> ${I}_base64_tmp | |
/bin/cat ${I}_base64_tmp | /usr/bin/tr -d '\r' | /usr/bin/tr -d '\n' > ${I}_base64 | |
/bin/rm -f ${I}_base64_tmp | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment