Skip to content

Instantly share code, notes, and snippets.

@gjergjsheldija
Created April 4, 2013 19:27
Show Gist options
  • Save gjergjsheldija/5313372 to your computer and use it in GitHub Desktop.
Save gjergjsheldija/5313372 to your computer and use it in GitHub Desktop.
create djvu books for subdirs of scanned images into low and hi res
#!/bin/sh
UNPAPER_OPTS_COMMON=" --mask-scan-threshold 0.01 --dpi 600 --mask-scan-size 100"
UNPAPER_OPTS_ST1=" --deskew-scan-size 5000 -dv 0.5"
UNPAPER_OPTS_ST2=" --no-noisefilter --no-blackfilter --no-grayfilter --no-blurfilter --no-deskew --border-align top --border-margin 150"
sdir=`pwd` #starting point; it is important that you start at the right place
dir=`find . -type d` #will save the sub/directory tree in var
for i in $dir; do
cd $i #go into directory
for file in $(ls *.jpg | sort -n); do
echo "converting : $file"
c44 $file ${file%%.*}_hi.djvu
convert $file ${file%%.*}_low.pbm;
unpaper --overwrite $UNPAPER_OPTS_COMMON $UNPAPER_OPTS_ST1 ${file%%.*}_low.pbm ${file%%.*}_1_low.pbm
unpaper --overwrite $UNPAPER_OPTS_COMMON $UNPAPER_OPTS_ST2 ${file%%.*}_1_low.pbm ${file%%.*}_low.pbm
cjb2 -clean ${file%%.*}_low.pbm ${file%%.*}_low.djvu
done
new_name=$(echo "$i" | tr -cs "[:alnum:]_" _)
echo "creating book file : $new_name.djvu"
djvm -c ${new_name}_hi.djvu $(ls *_hi.djvu | sort -n)
djvm -c ${new_name}_low.djvu $(ls *_low.djvu | sort -n)
echo "done."
echo "cleaning up.."
for file in $(ls *.jpg | sort -n); do
rm -f ${file%%.*}_hi.djvu
rm -f ${file%%.*}_low.djvu
rm -f ${file%%.*}_low.pbm
rm -f ${file%%.*}_1_low.pbm
done
cd ..
cd $sdir #go back to start
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment