Add new comment

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Submitted by xtecuan (registered user) on Thu, 2008-02-21 19:26.

Here some improvements to the bash script to convert .jpg  to .djvu file (any2djvu-low) , only on management of main folder to process and final extension of the djvu file:

#!/bin/sh
#
# FromJpegToBitonal.sh
# requires: anytopnm, ppmtopgm, pgmtopbm and cjb2
# Based on  any2djvu-low script  from: http://www.howtoforge.com/creating_djvu_documents_on_linux
# Modified by J. Rivera Pineda , xtecuan at gmail dot com
# Site: http://gente.debian.org.sv/~xtecuan/FromJpegToBitonal/


#$1 --- Path to Process
#$2 --- Extension like *.JPG or *.PNG etc

PBASEPATH=$1


if [ -d $PBASEPATH ]

then
    if [ -z `which anytopnm` -o -z `which ppmtopgm` -o -z `which pgmtopbm`\
        -o -z `which cjb2` ]; then
      usage
      echo "Error: anytopnm, ppmtopgm, pgmtopbm and cjb2 are needed"
      echo
      exit 1
    fi

    shopt -s extglob

    DEFMASK="*.JPG"
    DPI=300
    DEFAULT_PROC_DIR=JPGs
    # uncomment the following line to compile a bundled DjVu document
    #OUTFILE="#0-bw.djvu"

    function usage() {
      echo
      echo "usage:"
      echo
      echo "$0 [\"REGEXP\"]"
      echo "    converts single pages with the default mask $DEFMASK (or REGEXP if provided)"
      echo "    in the current directory to single-page black and white djvu documents"
      # uncomment the following line to compile a bundled DjVu document
      # echo "    and bundles them as a djvu file $OUTFILE"
      echo
    }

    if [ -n "$2" ]; then
      MASK=$2
    else
      MASK=$DEFMASK
    fi

    #

    if [ ! -d  ${PBASEPATH}/${DEFAULT_PROC_DIR} ]
    then
        echo "Making  ${PBASEPATH}/${DEFAULT_PROC_DIR}"
        mkdir  ${PBASEPATH}/${DEFAULT_PROC_DIR}
    fi

    for i in ${PBASEPATH}/$MASK; do
      newName=`basename $i ${MASK:1}`
      if [ ! -e $i ]; then
        usage
        echo "Error: current directory must contain files with the mask $MASK"
        echo
        exit 1
      fi
      if [ ! -e ${newName}.djvu ]; then
        echo "Current Processing $i"

        anytopnm ${i} | ppmtopgm | pgmtopbm -value 0.499 > ${PBASEPATH}/${newName}.pbm
        # in netpbm >= 10.23 the above line can be replaced with the following:
        # anytopnm $i | ppmtopgm | pamditherbw -value 0.499 > $.pbm
        cjb2 -dpi $DPI ${PBASEPATH}/${newName}.pbm ${PBASEPATH}/${newName}.djvu
        rm -f ${PBASEPATH}/${newName}.pbm
        echo "Moving $i to ${PBASEPATH}/${DEFAULT_PROC_DIR}/"
        mv $i ${PBASEPATH}/${DEFAULT_PROC_DIR}/
       
      fi
       
    done
    echo "Process ........[Done]"

    # uncomment the following line to compile a bundled DjVu document
    #djvm -c $OUTFILE $MASK.djvu
else
    echo " ${PBASEPATH} does not exists"
fi

 

The complete code: 

http://gente.debian.org.sv/~xtecuan/FromJpegToBitonal/0.1.1/FromJpegToBitonal.tar.bz2 


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.

Reply

*
*
The content of this field is kept private and will not be shown publicly.


*

  • Images can be added to this post.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <div>
  • Lines and paragraphs break automatically.