Created
January 16, 2011 23:42
-
-
Save jiphex/782274 to your computer and use it in GitHub Desktop.
Scans a document from the default scanner and emails it (securely) via GMail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# scans a single document and mails it | |
# | |
# Requirements: sane, ImageMagick, tesseract, gocr, sendemail | |
# It would be trivially email to remove gocr, tesseract is better it seems | |
# You could replace ImageMagick with anything that convert PBM > something. | |
SCANFILE=`mktemp /tmp/scantmp.XXXXXXXX` | |
PBMFILE="${SCANFILE}.pbm" | |
TIFFILE="${SCANFILE}.tif" | |
GOCRTXT="${SCANFILE}.gocr.txt" | |
TESSTXT="${SCANFILE}.tess" | |
OUTTXT="${SCANFILE}.msg" | |
JPGFILE="${SCANFILE}.jpg" | |
echo "Scanning to ${SCANFILE}.pbm..." | |
scanimage --mode=color > $PBMFILE | |
convert $PBMFILE $TIFFILE | |
convert $PBMFILE -quality 60% $JPGFILE | |
tesseract $TIFFILE $TESSTXT | |
TESSTXT="${TESSTXT}.txt" | |
gocr -i $PBMFILE -o $GOCRTXT | |
cat > $OUTTXT <<EOF | |
Hi, | |
I've scanned a document, the OCR text and JPEG image are attached below. | |
Regards, | |
Scanmatic. | |
----- BEGIN TESS TEXT ----- | |
`cat $TESSTXT` | |
----- END TESS TEXT ----- | |
----- BEGIN GOCR TEXT ----- | |
`cat $GOCRTXT` | |
----- END GOCR TEXT ----- | |
EOF | |
sendemail -s smtp.gmail.com:587 -o message-file=$OUTTXT -a $JPGFILE -t [email protected] -u "Document Scan `date`" -f [email protected] -o tls=yes -xu [email protected] -xp y0urGm4ilp4ssw0rd | |
rm -vf $PBMFILE $TIFFILE $GOCRTXT $SCANFILE $TESSTXT $OUTTXT $JPGFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment