Last active
December 21, 2015 03:09
-
-
Save tg123/6240128 to your computer and use it in GitHub Desktop.
Bash script to convert typescript to gif
Origin from http://blog.fedora-fr.org/metal3d/post/typescript-to-gif
This file contains 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 | |
# origin from http://blog.fedora-fr.org/metal3d/post/typescript-to-gif | |
# modified by tgic to specified output file | |
# http://www.imagemagick.org/script/command-line-options.php#limit | |
CONVERTARG="-limit memory 32MiB -limit map 64MiB" | |
TIMING=$1 | |
SCRIPT=$2 | |
OUTPUT=$3 | |
W=$WINDOWID | |
if [ ! -f "$TIMING" ] || [ ! -f "$SCRIPT" ] || [ "$OUTPUT" == "" ] | |
then | |
echo "usage: $0 TIMING SCRIPT OUTPUT" | |
exit | |
fi | |
if [ "$W" == "" ] | |
then | |
echo 'No window found use xvtypescripttogif instead' | |
exit | |
fi | |
WORKDIR=$(mktemp -d) | |
t=$(mktemp) | |
cp $SCRIPT $t | |
#remove first line | |
sed -i '1d' $t | |
#clear screen | |
clear | |
#read timing file one by one | |
curr=0 | |
i=0 | |
while read line | |
do | |
#capture time and chars to read | |
cols=($line) | |
chars=${cols[1]} | |
#read from current char the number of chars to read | |
dd if=$t bs=1 skip=$curr count=$chars 2>/dev/null | |
#convert to gif frame with a nice frame-number | |
n=$(printf "%010d" $i) | |
import -window $WINDOWID $WORKDIR/$n.gif | |
#and move to next position | |
curr=$((curr+chars)) | |
i=$((i+1)) | |
done <$TIMING | |
rm -f $t | |
#now, set gif with delay per frame | |
i=1 | |
while read line | |
do | |
cols=($line) | |
timing=${cols[0]} | |
#get next image | |
file=$(ls -1 $WORKDIR | head -n $i | tail -n 1) | |
timing=$(echo "$timing*100" | bc -l | awk '{print int($0)}') | |
command=$command" -delay $timing $WORKDIR/$file" | |
i=$((i+1)) | |
done < $TIMING | |
convert $CONVERTARG $command $WORKDIR/anim-notoptim.gif | |
convert $CONVERTARG $WORKDIR/anim-notoptim.gif -coalesce -layers Optimize $OUTPUT | |
rm -rf $WORKDIR |
This file contains 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 | |
BASEDIR=$(dirname $(readlink -f $0)) | |
xvfb-run --server-args="-screen 0, 640x480x24" gnome-terminal -e "$BASEDIR/typescripttogif $*" --working-directory=`pwd` --hide-menubar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment