#!/bin/bash -e
if [[ -z "$4" ]]; then cat <<EOF
photog-preview: Composes images to together to create an album preview
Usage: photog-preview img1.jpg img2.jpg img3.jpg [...] preview.jpg
Note: Album previews MUST consist of 3, 6 or 9 images
EOF
exit; fi
# The "xc:red" is a workaround for the following ImageMagick bug:
b=8
if (($# == 4))
then
convert -bordercolor black xc:red \
\( "$1" -border $b -resize 200x1000 \) \
\( "$2" -border $b -resize 200x1000 \) \
\( "$3" -border $b -resize 200x1000 \) \
-append -crop +0+1 -shave 2 +repage "$4"
elif (($# == 7))
then
convert -bordercolor black \
\( \( xc:red \) \
\( "$1" -border $b \) \
\( "$2" -border $b \) \
+append -crop +1+0 +repage -resize 400x1000 \) \
\( \( xc:red \) \
\( "$3" -border $b \) \
\( "$4" -border $b \) \
+append -crop +1+0 +repage -resize 400x1000 \) \
\( \( xc:red \) \
\( "$5" -border $b \) \
\( "$6" -border $b \) \
+append -crop +1+0 +repage -resize 400x1000 \) \
-append -shave 2 "$7"
elif (($# == 10))
then
convert -bordercolor black \
\( \( xc:red \) \
\( "$1" -border $b \) \
\( "$2" -border $b \) \
\( "$3" -border $b \) \
+append -crop +1+0 +repage -resize 600x1000 \) \
\( \( xc:red \) \
\( "$4" -border $b \) \
\( "$5" -border $b \) \
\( "$6" -border $b \) \
+append -crop +1+0 +repage -resize 600x1000 \) \
\( \( xc:red \) \
\( "$7" -border $b \) \
\( "$8" -border $b \) \
\( "$9" -border $b \) \
+append -crop +1+0 +repage -resize 600x1000 \) \
-append -shave 2 "${10}"
else
echo "Incorrect number of arguments" >&2
exit 1
fi