Skip to content

Instantly share code, notes, and snippets.

@danton721
Last active February 14, 2021 05:27
Show Gist options
  • Save danton721/12896b1c6402a1b785a4b84628ed0be1 to your computer and use it in GitHub Desktop.
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
#!/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