Last active
February 14, 2021 05:27
-
-
Save danton721/12896b1c6402a1b785a4b84628ed0be1 to your computer and use it in GitHub Desktop.
Decode base64 from a CSV with header "ID, Base64" to ./exports/id.png
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 | |
# Purpose: Read Comma Separated CSV File w/ id,base64 ecoded PNG and convert to PNG file | |
# Author: Vivek Gite under GPL v2.0+ (CSV parser) and Base64 changes by Danton Heuer under GPL v2.0+ | |
# Usage: $ sh ./convert.sh filename.csv | |
echo "Converting Base64 to PNG from CSV file '$1' to ./exports folder" | |
mkdir -p exports | |
INPUT="$1" | |
OLDIFS=$IFS | |
IFS=',' | |
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } | |
while read id base | |
do | |
echo "Converting $id" | |
(echo -n "${base}" | sed "s|data:image/png;base64,||g") | base64 -di > "./exports/""$id"".png" | |
done < $INPUT | |
IFS=$OLDIFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment