- # final convert and clean
- convert $convertflags $dir/upg-${pgn}-?.pnm $dir/upg-${pgn}-%01d.tiff || exit 1
-
+ #detect if the page is 2-up
+ for subpg in $($my_seq 1 2); do
+ echo Processing subpg ${subpg}.
+ if $(dirname $0)/detect2pages.sh $dir/upg-${pgn}-${subpg}.pnm ${pgn} ${subpg}; then
+ if [[ $verbose == 1 ]]; then
+ echo "Resplitting subpg ${subpg}."
+ fi
+ unpaper $unpaperflags --pre-rotate 90 --layout double --overwrite --no-blackfilter -op 2 $dir/upg-${pgn}-${subpg}.pnm $dir/upg-${pgn}-${subpg}-%01d.pnm
+ else
+ cp $dir/upg-${pgn}-${subpg}.pnm $dir/upg-${pgn}-${subpg}-1.pnm
+ fi;
+
+ done;
+
+ #final convert and clean w/ bebook optimisation
+ if [[ $bebook ]]; then
+ convert $convertflags -colorspace Gray -median 1 $dir/upg-${pgn}-1-?.pnm -trim -resize 1800x2400 $dir/final-${pgn}-1-%01d.${extension} || exit 1
+ convert $convertflags -colorspace Gray -median 1 $dir/upg-${pgn}-2-?.pnm -trim -resize 1800x2400 $dir/final-${pgn}-2-%01d.${extension} || exit 1
+ else
+ convert $convertflags $dir/upg-${pgn}-1-?.pnm $dir/final-${pgn}-1-%01d.${extension} || exit 1
+ convert $convertflags $dir/upg-${pgn}-2-?.pnm $dir/final-${pgn}-2-%01d.${extension} || exit 1
+ fi