Semi-automating your image scanning in Linux

Semi-automating your image scanning in Linux

I recently found myself having to scan about 20 booklets of around 10 pages each. I could obviously just fire up GIMP/XSane and go the point and click route, but doing the same thing 200 times gets b000ring. Here's my somewhat optimized workflow I came up with.

🐧
This is quite Linux specific, and of less use to people on other OSes. Both Sane and Imagemagick are available on both Win and Mac though, so you could probably cobble together something similar 😀.

The setup

First, make sure that Sane (scanimage command) and Imagemagick (convert command) is installed.

Now let's add the following aliases to your .zshrc (or .bashrc or similar):

# Scan a single image in grayscale, e.g. "scang gray.jpg".
alias scang="scanimage -d epsonds:net:192.168.88.88 --depth 8 --resolution 300 --mode Gray -o"

# Scan a single image in color, e.g. "scanc color.jpg".
alias scanc="scanimage -d epsonds:net:192.168.88.88 --depth 8 --resolution 300 --mode Color -o"

# Scan a batch of grayscale images, e.g. "scangb".
alias scangb="scanimage -d epsonds:net:192.168.88.88 --depth 8 --resolution 300 --format jpeg --batch-prompt --batch=scan-%03d.jpg --mode Gray "

# Scan a batch of color images, e.g. "scancb".
alias scancb="scanimage -d epsonds:net:192.168.88.88 --depth 8 --resolution 300 --format jpeg --batch-prompt --batch=scan-%03d.jpg --mode Color"

Yes yes, I know you got some extra aliases for free...you're welcome 😉
All you need to do is change the -d (device). You can list all your available devices with scanimage -L.

That's it - that's all you need for a decent scanning pipeline.

The workflow

Start out by simply issuing the scancb command to start scanning a batch in color.

$ scancb                                                                      ✔ 
Scanning infinity pages, incrementing by 1, numbering from 1
Place document no. 1 on the scanner.
Press <RETURN> to continue.
Press Ctrl + D (EOF) to terminate.

Keep pressing enter and changing page in the scanner until you're done, and then finally press Ctrl+d. You'll end up with a bunch of files named scan-001.jpg, scan-002.jpg etc.

Now simply run the command convert *.jpg myfile.pdf, and you'll end up with a PDF with all the pages in the correct order - yay! 🎉

Bonus tip

I needed to rotate and crop my images slightly. I simply did that using Gwenview (Ctrl+Shift+R, Shift+C) while I was waiting for the scanning to happen.