From 41e9a60660775725a3f2792842ee0c046f6eb0ff Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 14 Nov 2019 09:21:00 +0100 Subject: [PATCH] [enh] adds page generator --- page_generator.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 page_generator.sh diff --git a/page_generator.sh b/page_generator.sh new file mode 100755 index 0000000..113b6cf --- /dev/null +++ b/page_generator.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +IMG=$1 +COUNT_HORIZONTAL=$2 +COUNT_VERTICAL=$3 +LANDSCAPE=${4} + +panic(){ echo $@; exit 2; } + +[[ ! -f $IMG ]] && panic "$IMG does not exist" + +SMALL_SIDE=4000 +LARGE_SIDE=5800 + +# /tmp/out.pdf PDF 567x822 567x822+0+0 16-bit sRGB 980KB 0.010u 0:00.009 +read name type GEOMETRY canvas depth format size other <<< $( identify $IMG ) +IMG_WIDTH=$( cut -d "x" -f 1 <<< $GEOMETRY ) +IMG_HEIGHT=$( cut -d "x" -f 2 <<< $GEOMETRY ) + +TOTAL_WIDTH=$( [[ -n "$LANDSCAPE" ]] && echo $LARGE_SIDE || echo $SMALL_SIDE ) +TOTAL_HEIGHT=$( [[ -n "$LANDSCAPE" ]] && echo $SMALL_SIDE || echo $LARGE_SIDE ) + +REQ_WIDTH=$(( $TOTAL_WIDTH / $COUNT_HORIZONTAL )) +REQ_HEIGHT=$(( $TOTAL_HEIGHT / $COUNT_VERTICAL )) + +DUP=$(( ( $COUNT_HORIZONTAL * $COUNT_VERTICAL ) - 1 )) + +DATE=$( date +%s ) +OUTPUT_DIR=/tmp +FILENAME=$( basename $IMG ) +PDF_NAME=${OUTPUT_DIR}/${DATE}_${FILENAME}.pdf +OUT=$( montage -tile ${COUNT_HORIZONTAL}x${COUNT_VERTICAL} -density 200x200 -units pixelspercentimeter -border 0 -page ${TOTAL_WIDTH}x${TOTAL_HEIGHT} "$IMG" -geometry ${REQ_WIDTH}x${REQ_HEIGHT} -duplicate ${DUP},0 ${PDF_NAME} ) + +[ 0 -eq $? ] && echo $PDF_NAME || panic "An error occured... $OUT"