Image Grid from SSTV pictures

During January 2019 there were two weekends with SSTV activity from ISS. As it would be nice to have all received images in a grid I amde a little shell script to accomplish this. You just need to rename the input picture according to the numbers of the images like 01_whatsoever.png. Missing images will be replaced by a dummy saying “picture missing”. Output is a file named output.png. The script assumes that input image size is 640x496 pixels and output is hardcoded 2560x1488. An output example:

Output sample from the Jan 2019 mission
Output sample from the Jan 2019 mission

And here is the script code:

#!/bin/sh
#
# v0.1 Florian Wolters DF2ET
#
# This script takes 12 input images named 01_something, 02_something ...
# and alignes them in a 4x3 matrix. Missing pics will be replaced by a 
# dummy

convert -size 2560x1488 xc:transparent output.png
x=0;
y=0;
for file in 01_* 02_* 03_* 04_* 05_* 06_* 07_* 08_* 09_* 10_* 11_* 12_*; do
   if [ -f $file ]; then
      echo "$file placed @ x: $x; y: $y"
   else
      if [ ! -f temp.png ]; then
         convert -size 640x496 xc:black temp.png
         convert temp.png -font Arial -weight 700  -pointsize 80 -draw "rotate -45 gravity center fill yellow text 0,0 'picture missing' " temp.png
      fi
      file="temp.png"
      echo "inserting dummy @ x: $x; y: $y"
   fi
   composite -geometry 640x496+$x+$y $file output.png output.png
   if [ "$x" -lt "1920" ]; then
      x=$(echo "$x + 640" | bc)
   else
      y=$(echo "$y + 496" | bc)
      x=0
   fi
done
rm -f temp.png
exit 0