OPTIONS:
-v: Be verbose.
-d depth: Use given depth. Default is 1. Unpaper can only handle up to 8.
+ -D dpi: Use given DPI. Colour scans on library scanners are usually 300, bw 400.
-s: skip masking/trimming. Overrides -m.
-f: Forceably redo everything.
-p: Forceably redo pdf conversion. Implies options below, equivalent to -f.
convertflags=
unpaperflags=
depthflags="-depth 1"
+dpi=
skipmask=
+verbose=
while getopts 'vd:sfpmuc' OPTION
do
case $OPTION in
- v) convertflags="$convertflags -verbose"
+ v) verbose=1
+ convertflags="$convertflags -verbose"
unpaperflags="$unpaperflags -v --time"
;;
d) depthflags="-depth $OPTARG"
;;
+ D) dpi=$OPTARG
+ ;;
s) skipmask=1;
;;
f) forcepdf=1; forcemask=1; forceunpaper=1; forceclean=1
echo "Got $pages page(s)."
rm $dscname
+# guess at DPI, unless it's been set
+# the scans do not seem to accurately reflect their resolution.
+if [[ "$dpi" = "" ]]; then
+ # %k gives the number of colours/shades in the image.
+ # 2 for b/w, and the scanner seems to default to 400 dpi for that
+ # 256 for greyscale, which has to be selected manually (so I'm assuming 300 for no good reason)
+ # 31564 for colour, which defaults to 300
+ if [[ $( convert $file[0] -format "%k" info: || exit 1 ) == 2 ]]; then
+ dpi=400;
+ else
+ dpi=300
+ fi
+ if [[ $verbose == 1 ]]; then
+ echo "DPI guessed at $dpi."
+ fi
+fi
+
# process pages 1 by 1 to avoid convert gobbling all the memory
for pg in `$my_seq 1 $pages`; do
echo "Processing page $pg."
# convert from pdf
origpnm=$dir/pg-${pgn}.pnm
if [[ ! $([ -e $origpnm ]) || $forcepdf ]]; then
- convert $convertflags $depthflags -density 300 $file[$(expr $pg - 1)] \
+ convert $convertflags $depthflags -density $dpi $file[$(expr $pg - 1)] \
$origpnm || exit 1
fi;