Advertisement
Guest User

any2djvu-bw.sh

a guest
May 8th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.30 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # >> any2djvu-bw.sh <<
  4. #
  5.  
  6. if [ -z `which anytopnm` -o -z `which ppmtopgm` -o -z `which pgmtopbm`\
  7. -o -z `which cjb2` ]; then
  8. usage
  9. echo "Error: anytopnm, ppmtopgm, pgmtopbm and cjb2 are needed"
  10. echo
  11. exit 1
  12. fi
  13.  
  14. shopt -s extglob
  15.  
  16. # DEFMASK="*.jpg"
  17. DEFMASK="*.jpg"
  18. DPI=150
  19. # uncomment the following line to compile a bundled DjVu document
  20. OUTFILE="#0-bw.djvu"
  21.  
  22. function usage() {
  23. echo
  24. echo "usage:"
  25. echo
  26. echo "$0 [\"REGEXP\"]"
  27. echo " converts single pages with the default mask $DEFMASK (or REGEXP if provided)"
  28. echo " in the current directory to single-page black and white djvu documents"
  29. # uncomment the following line to compile a bundled DjVu document
  30. echo " and bundles them as a djvu file $OUTFILE"
  31. echo
  32. }
  33.  
  34. if [ -n "$1" ]; then
  35. MASK=$1
  36. else
  37. MASK=$DEFMASK
  38. fi
  39.  
  40. for i in $MASK; do
  41. if [ ! -e $i ]; then
  42. usage
  43. echo "Error: current directory must contain files with the mask $MASK"
  44. echo
  45. exit 1
  46. fi
  47. if [ ! -e $i.djvu ]; then
  48. echo "$i"
  49. anytopnm $i | ppmtopgm | pgmtopbm -value 0.499 > $i.pbm
  50. # in netpbm >= 10.23 the above line can be replaced with the following:
  51. # anytopnm $i | ppmtopgm | pamditherbw -value 0.499 > $.pbm
  52. cjb2 -dpi $DPI $i.pbm $i.djvu
  53. rm -f $i.pbm
  54. fi
  55. done
  56.  
  57. # uncomment the following line to compile a bundled DjVu document
  58. djvm -c $OUTFILE $MASK.djvu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement