Every piece of (useful) snail mail I receive is scanned and stored both on my computer and on a remote backup server. The scanner itself cost me around 50€ (it’s a Canon LIDE 50 of which I am quite happy, especially since it is perfectly compatible with the latest SANE libraries on my Ubuntu). In order to improve the efficiency of the process in terms of time I have to waste doing things, I have written a short script that interacts with sane (for scanning) and ncftp (for uploading to the backup server) and lets me enter elementary information on the command line.
Here is the code:
let prompt s = print_string s ; flush stdout let make_directory dirname = let command = "mkdir " ^ dirname in 0 = Sys.command command let base_path = "/home/arkadir/docs/" let scan_command = "scanimage -l 0 -t 0 -x 215 -y 297 --brightness -22 --contrast 22 --resolutio\ n 300 --progress --mode Gray --format=tiff 2> /dev/null" let scan_to_file filename = let command = scan_command ^ " | convert tiff:- " ^ filename in 0 = Sys.command command let scan_files base = let rec aux i = let filename = base ^ "/page" ^ string_of_int i ^ ".png" in if scan_to_file filename then begin ignore (Sys.command ("display " ^ filename)); prompt "Scan successful. Enter any string to continue, nothing to stop. " ; let line = read_line () in if line <> "" then aux (i+1) end else begin prompt "Scan FAILED. Enter any string to retry. " ; let line = read_line () in if line <> "" then aux i end in aux 1 let rec upload_files dirname = print_endline "Uploading files..." ; let command = "ncftpput -R -f "^base_path^"ftp.cfg scans "^dirname in if 0 <> Sys.command command then begin prompt "Upload FAILED! Enter any string to retry. " ; let line = read_line () in if line <> "" then upload_files dirname end let process = prompt "Document name: " ; let line = read_line () in if line = "" then print_endline "No filename entered, aborting." else let dirname = base_path ^ line in if not (make_directory dirname) then print_endline ("Could not create directory " ^ dirname ^ ", aborting.") else begin scan_files dirname; upload_files dirname end
So far, I’m keeping the data as high-resolution PNG files, which means about 8MiB for every file. I will be moving to the DjVu compression format as soon as possible, and update my script accordingly.
1 Responses to “Scanners!”
Leave a Reply