How to scan documents from a command-line interface on Linux

Scanimage is a command-line interface to control image acquisition devices such as flatbed scanners or cameras. The device is controlled via command-line options.

After command-line processing, scanimage normally proceeds to acquire an image. The image data is written to standard output in one of the PNM (portable aNyMaP) formats (PBM for black-and-white images, PGM for grayscale images, and PPM for color images), TIFF format (black-and-white, grayscale or color), PNG format, or JPEG format. scanimage accesses image acquisition devices through the SANE (Scanner Access Now Easy) interface and can thus support any device for which there exists a SANE backend (try apropos sane- to get a list of available backends).

The simple syntax of the scanimage command

It’s easy to use and it has a simple syntax.

To get a list of devices:

$ scanimage -L

To scan with default settings to the file image.pnm:

$ scanimage >image.pnm

To scan 100×100 mm to the file image.tiff (-x and -y may not be available with all devices):

$ scanimage -x 100 -y 100 --format=tiff >image.tiff

To print all available options:

$ scanimage -h

How to install scanimage on your Linux distribution

The first step on the road to successful scanning is to install libsane, which has the central library for operating scanners. The package also provides SANE’s collection of scanner backends. If the scanner is not supported by SANE, the backend (and other files) will have to be obtained from the distribution archives or the vendor. A notable free backend source requiring this step is the one for the all-in-one machines from HP.

Fortunately, scanimage is installed by default on the main Linux distribution. If not, you can try to install it with your package manager:

$ sudo apt/dnf/zypper libsane

Sources and references