Created
April 4, 2019 20:55
-
-
Save ntorga/e0cb6b5a60f75cb5b01e2b30c157028e to your computer and use it in GitHub Desktop.
Decode base64 images into media files and replace the original file with WordPress upload folder. You need to upload the images into /wp-content/uploads/ after finishing.
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/bash | |
file=${1} | |
for extension in png jpeg jpg gif bmp; do | |
for image in `grep -ho "data:image/${extension};base64,[A-Za-z0-9+/=]*" ${file}`; do | |
image_signature=$(echo ${image} | md5sum | awk '{print $1}') | |
echo ${image} > ${image_signature}.hash | |
rm -f to-replace.script | |
echo "s|$(cat ${image_signature}.hash)|/wp-content/uploads/${image_signature}.${extension}|g" > to-replace.script | |
sed -i -f to-replace.script ${file} | |
sed -i "s|data:image/${extension};base64,||g" ${image_signature}.hash | |
cat ${image_signature}.hash | base64 -d > ${image_signature}.${extension} | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment