Stitching 4 photos in 1

I realised I had a lot of low-res photos from WhatsApp that were still worth printing. However if you’d send it straight to the printer this way they would look very bad.

So my thinking was: let’s print them quarter-size! But no printing service in the Netherlands can do that, apparently. So the next idea was to combine four photos in 1 and cut them myself.

I tried to do this in Affinity Photo, but I very quickly decided doing this manually for 150 photos was no fun at all. Manual labour sucks, computers are better at this!

And it’s easy peasy with GraphgicsMagick (or ImageMagick).

Usage

Install GraphicsMagick (brew install graphicsmagick). You can also use ImageMagick, in that case remove the gm from the script. I prefer GraphicsMagick as the image-quality is slightly better and it’s faster.

Copy all the photos you want combined into a single folder. Copy the script to the same folder (on a Mac you can copy the code below and do: pbpaste > crop_and_combine.sh; chmod +x crop_and_combine.sh). Then run the script ;) (./crop_and_combine.sh)

count=0
files=""
mkdir result

for i in *.jpg
do
  let count=count+1
  files=$files" "\"$i\"
  let four=count%4
  cp "$i" /tmp/$four.jpg
  gm convert /tmp/$four.jpg -rotate "90>" -resize "1800x2700^" \
    -gravity center -crop 1800x2700+0+0 +repage /tmp/$four.c.tiff;
  if [ "$four" -eq 0 ]
  then
    gm convert -append /tmp/1.c.tiff /tmp/2.c.tiff /tmp/v1.tiff;
    gm convert -append /tmp/3.c.tiff /tmp/0.c.tiff /tmp/v2.tiff;
    gm convert +append /tmp/v1.tiff /tmp/v2.tiff result/$count.jpg
  fi
done

if [ "$four" -ne 0 ]
then
  gm convert -append /tmp/1.c.tiff /tmp/2.c.tiff /tmp/v1.tiff;
  gm convert -append /tmp/3.c.tiff /tmp/0.c.tiff /tmp/v2.tiff;
  gm convert +append /tmp/v1.tiff /tmp/v2.tiff result/$count.jpg
fi

A quick rundown of the script:

Result!

Here’s four photos and the resulting stitch: Resulting images