Skip to content

Instantly share code, notes, and snippets.

@gorenje
Last active September 29, 2016 18:30
Show Gist options
  • Save gorenje/0facfffabfbc8a38c7c3d00674da34f6 to your computer and use it in GitHub Desktop.
Save gorenje/0facfffabfbc8a38c7c3d00674da34f6 to your computer and use it in GitHub Desktop.
Store motion animated gif

Start screencapture in terminal, a single character will trigger a screencapture:

function _start_screencapture
{
    for n in `seq -f %03g 0 100` ; do
        if read -n 1 ; then
            screencapture -t png ~/Desktop/capture-${n}.png
            echo "Taken " ${n}
        fi
    done
}
alias start_screencapture=_start_screencapture

if the first 100 frames are reversible, then use this to copy the first 100 frames, in reverse order, to be the second 100 frames:

function copy_100_to_200
{
    for n in `seq -f %03g 1 99` ; do
        m=`expr 200 - $n`
        cp capture-${n}.png capture-${m}.png
    done
}

Crop the png in situ:

for n in *.png ; do mogrify -crop 973x862+290+184 $n ; echo $n ; done

where 973x862+290+184 needs to be obtained by taking the largest png and find the biggest cropping area. 973x862+290+184 means: widthxheight+x+y where (x,y) is the top-left corner of the crop rectangle.

Convert png to jpg:

for n in `seq -f %03g 0 199` ; do convert capture-${n}.png -quality 100% capture-${n}.jpg ; done

Create animated gif:

convert capture-*.jpg -delay 1 -loop 0 result.gif

Examples, created using patterns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment