Daily Driver: To GIF and Back

When rendering my vehicles I generate a single PNG containing all frames. Playdate SDK calls these image tables, or more specifically matrix image tables. You could also call them sprite-sheets, with the one qualification that every sprite has the same dimensions.

Given that these are plain old images they can be viewed easily. Showing a grid on top of the image makes the layout obvious. You can edit the image as a whole easily enough, but what if you want to adjust the size of every cell? Then we have a problem.

There are a few apps that can load image tables, asking for the cell size during loading. My favourite such app is Piskel which has good options for import, editing, and export.

However there is another type of image that consists of multiple frames of the same dimensions: the Animated GIF. There are far more apps that can deal with this format, such as Acorn or Adobe Photoshop.


How can we convert a matrix image table to Animated GIF, and back again?


We could use Piskel, but its GUI isn’t the most straightforward so using it twice at separate points in the conversion process gets old fast.

So I had the idea of writing a couple of small shell scripts that leverage imagemagick and can be run from my Makefile, the command-line, macOS context menu, or all of the above.


Below are both scripts, be sure to grab the Gist versions as they have error checking and “help” usage display.

Convert image table to Animated GIF


# input file details
fullname=$(basename -- "$1")

# extract cell size from filename
if [[ $filename =~ $regex ]]

# convert to Animated GIF
magick -dispose previous -delay 1 -loop 0 $1 +repage -crop ${W}x${H} +repage ${filename}.gif

# output specifications
magick identify -format "${filename}.gif: %n frames\n" ${filename}.gif

Convert Animated GIF to image table


# input file details
fullname=$(basename -- "$1")

# convert to image table PNG
magick montage $1 -tile 32x -geometry '1x1+0+0<' -alpha On -background "rgba(0, 0, 0, 0.0)" ${filename}.png

# output specifications
magick identify -format "${filename}.png: %w x %h pixels\n" ${filename}.png
Enjoyed this blog post? Send blog thanks!
Pay what you want, using PayPal or Stripe
Comments: @gingerbeardman