LinuxCommandLibrary

scanimage

Scan images from a scanner device

TLDR

List available scanners to ensure the target device is connected and recognized

$ scanimage [[-L|--list-devices]]
copy

Scan an image and save it to a file
$ scanimage --format [pnm|tiff|png|jpeg|pdf|...] > [path/to/new_image]
copy

Specify the device to scan from
$ scanimage [[-d|--device]] [device_name] > [path/to/new_image]
copy

Specify resolution for the scanned image (default resolution is 75dpi)
$ scanimage --resolution [300] > [path/to/new_image]
copy

SYNOPSIS

scanimage [OPTIONS]... [> image-file]

PARAMETERS

-L, --list-devices
    Lists all available scanner devices detected by SANE.

-d device, --device-name device
    Selects a specific scanner device to use. The device name can be found using --list-devices.

--format format
    Specifies the output image format. Common formats include 'pnm' (default) and 'tiff'.

-o file, --output-file file
    Writes the acquired image data directly to the specified file instead of standard output.

--resolution dpi
    Sets the scanning resolution in dots per inch (DPI). Common values are 100, 200, 300, 600.

--mode mode
    Sets the scan mode. Possible values often include 'Lineart' (black and white), 'Gray' (grayscale), and 'Color'.

--source source
    Selects the scan input source, such as 'Flatbed', 'ADF' (Automatic Document Feeder), or 'Transparency.

--brightness value
    Adjusts the brightness level of the scan. The range of values is device-dependent.

--contrast value
    Adjusts the contrast level of the scan. The range of values is device-dependent.

-x width, -y height
    Sets the width and height of the scan area in millimeters.

-l left, -t top
    Sets the top-left corner coordinates (X and Y) of the scan area in millimeters.

--batch[=format]
    Enables batch scanning mode, useful for ADF. Optionally specify output format, e.g., 'scanimage --batch=scan_%03d.pnm'.

--batch-start num
    Sets the starting number for batch scan filenames.

--batch-count num
    Sets the total number of images to scan in batch mode.

-h, --help
    Displays a general help message and basic options.

-A, --advanced-options
    Displays all advanced and device-specific options available for the selected scanner.

DESCRIPTION

scanimage is a command-line program designed to control image acquisition devices such as flatbed scanners, handheld scanners, and video cameras. It serves as the official command-line interface for the SANE (Scanner Access Now Easy) project, providing a standardized way to access various scanning hardware on Unix-like operating systems.

This utility enables users to scan documents or images directly from the terminal, making it highly suitable for scripting, automation, and batch processing tasks. It supports various image formats, primarily PNM (PBM, PGM, PPM) and TIFF, and outputs the acquired image data to standard output, which is typically redirected to a file.

scanimage offers a comprehensive set of options to control scanning parameters like resolution, color mode (lineart, grayscale, color), scan area, brightness, and contrast. The availability of these options largely depends on the capabilities of the specific scanner and its corresponding SANE backend driver.

CAVEATS

scanimage's functionality is entirely dependent on the presence and proper configuration of SANE backends (drivers) for your specific scanner model. If a backend is not available or not correctly configured (e.g., in /etc/sane.d/), scanimage will not be able to detect or operate the scanner.

Users often need appropriate permissions (e.g., membership in the 'scanner' group or correct udev rules) to access the scanner device directly. Without proper permissions, the command may report 'Permission denied' errors.

By default, scanimage writes image data to standard output. For saving to a file, output redirection (e.g., > image.pnm) or the --output-file option is necessary.

DEVICE-SPECIFIC OPTIONS

Many options available with scanimage are not universal but are specific to the selected scanner device and its SANE backend. To see a complete list of options for your particular scanner, use the command: scanimage -d your_device_name --help or scanimage -d your_device_name -A. This will display all adjustable parameters, including resolution ranges, available modes, and unique features of your hardware.

EXIT STATUS AND ERROR HANDLING

scanimage typically exits with a status code of 0 upon successful completion. A non-zero exit status indicates an error during the scanning process (e.g., device not found, permission issues, or scanning failure). Diagnostic messages are usually printed to standard error (stderr) to provide more details about the problem, which can be useful for debugging automated scripts.

HISTORY

scanimage is a foundational component of the SANE (Scanner Access Now Easy) project, which commenced in 1996. The project's genesis was to establish a standardized application programming interface (API) for accessing diverse image acquisition devices, thereby bridging the gap in scanner support on Unix-like operating systems compared to proprietary OS counterparts.

As the primary command-line tool, scanimage has consistently served as a testament to the versatility of the SANE backend architecture. Its evolution is intrinsically linked to the broader SANE objective of fostering universal scanner compatibility through community-driven, open-source driver development.

SEE ALSO

sane-find-scanner(1), sane(7), xsane(1), gscan2pdf(1)

Copied to clipboard