#!/usr/bin/env bash # you need imagemagick or graphicsmagick, also sed and zip tmp_dir=$(mktemp --directory --tmpdir tmp.XXXXXXXXXX) name_with_ext=$(basename $1) name="${name_with_ext%.*}" echo "Removing old files..." rm -f ./$name*csv* # don't use gifs that have 'csv' in the name convert $1 -flip $tmp_dir/flipped-$1 # tableau's origin is different than imagemagick's echo "Splitting apart $1 into frames..." convert $tmp_dir/flipped-$1 -coalesce $tmp_dir/$name-frame-%06d.png # we wont ever have more than a million frames, will we? real_count=$(ls -1 $tmp_dir | grep $name-frame- | wc -l) count=$(($real_count - 1)) echo "Found $real_count frames in $1" echo '"x","y","r","g","b","frame"' >> $name.csv for FRAME in `seq -f %06g 0 $count`; do echo "Adding frame $FRAME to $name.csv..." convert $tmp_dir/$name-frame-$FRAME.png $tmp_dir/$name-frame-$FRAME.txt sed "s/^\([0-9]\{1,3\}\),\([0-9]\{1,3\}\): ([ ]*\([0-9]\{1,3\}\),[ ]*\([0-9]\{1,3\}\),[ ]*\([0-9]\{1,3\}\).*/\1,\2,\3,\4,\5,$FRAME/g" $tmp_dir/$name-frame-$FRAME.txt >> $name.csv # agh done echo "Created '$name.csv'" echo "Zipping up $name.csv to $name.zip..." rm -f ./$name.zip zip $name.zip $name.csv -q echo "Cleaning up..." rm -rf $tmp_dir echo "All done!"