Page 1 of 1

HOWTO : batch composite picture of large collection

Posted: 2015-01-30T08:15:02-07:00
by contremaitre
Hi,

I'd like to share my script.
It takes all pictures in a folder and creates multiple composite pictures.
The number of pictures in each composite output is a parameter of the script.

The issues this script address are :
- Using montage directly on a large picture set results in high memory usage, as it reads all pictures at once before rendering
- Resize input picture before processing.
- Automaticaly turns the pictures to have a good ratio

Usage : set the parameters at the top of the script, and run it in the folder you have your pictures.

Here is the script :

Code: Select all

#!/bin/bash
#Parameters
ROW=2
COLUMN=1
EXTENSION=*.JPG
OUTPUT_DIR=montage21
OUTPUT_NAME=montage.jpg
#max width (or height) of input picture, 0 to disable
MAX_INPUT_WIDTH=1000
#end parameters

let picNumber=${COLUMN}*${ROW}
echo $picNumber
TILE=${COLUMN}x${ROW}
if [ "$ROW" -lt "$COLUMN" ]; then
  ROTATE_SIGN="<"
else
  ROTATE_SIGN=">"
fi
RESIZE=""
if [ "$MAX_INPUT_WIDTH" -gt 0 ]; then
  RESIZE="-resize $MAX_INPUT_WIDTH"x"$MAX_INPUT_WIDTH"
fi
ROTATE="-90$ROTATE_SIGN"
mkdir -p $OUTPUT_DIR
files=($EXTENSION)
for (( i=0; i<${#files[@]} ; i+=$picNumber )) ; do
    echo "processing ${files[@]:$i:$picNumber}"
    convert ${files[@]:$i:$picNumber} $RESIZE -rotate $ROTATE miff:-|montage - -tile ${ROW}x${COLUMN}  -geometry +0+0 $OUTPUT_DIR/${files[$i]}
done