LinuxDevCenter.com

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things Linux across O'Reilly!

Search
Search Tips

advertisement

Listen Print Subscribe to Linux Subscribe to Newsletters
Linux & Unix > Excerpts >
Living Linux

Scanning Images With SANE

07/18/2000

SANE, "Scanner Access Now Easy," is the de facto Linux scanner interface, which you use to scan an image from an image scanning device -- such as a flatbed scanner -- and save it to an image file.

The SANE tools are available in the Debian sane package or on the Web at http://www.mostang.com/sane/.

As the acronym implies, getting a scanner to work on a Linux system hasn't always been smooth going. The SANE interface is completely open, and its developers are making sure that it is generalized enough to be implementable on any hardware or operating system.

SANE works with a wide array of scanning hardware, but you'll want to make sure the scanning hardware you want to use is compatible by checking the Hardware HOWTO and SANE's list of supported scanners.

Once you have SANE installed and going, you can scan images with applications like the GIMP image editor; do this to scan images with a self-explanatory, point-and-click interface. The rest of this column focuses on a command-line scanimage tool, which comes with the SANE package.

Listing your scanner devices

You'll need to know the names of your scanner devices before you can use them. Get them by using scanimage with the --list-devices option:

scanimage --list-devices
device 'umax:/dev/sgb' is a 
  UMAX   Astra 1220S   flatbed scanner

In this example, there's one scanning device on this system, a UMAX scanner which can be used to scan by using its device name, 'umax:/dev/sgb,' as an argument to the -d option.

To list the available resolutions and options that are supported by a particular device, use the --help option along with the -d option followed by its device name.

For example, to list available options supported by the device listed above, you'd type:

scanimage --help -d 'umax:/dev/sgb'

For all scanimage commands, to specify the scanner device you want to use, include the -d option with the device name.

Making sure your scanner works

To test a scanner and make sure it works, use the --test option, which performs diagnostic tests to make sure that the scanner is being read from properly.

For example, to test the scanner device from the above example, you'd type:

scanimage --test -d 'umax:/dev/sgb'

Scanning an image

To scan an image with scanimage, most scanning devices let you specify the x and y values, in pixels, for the image size to scan as arguments to the -x and -y options from the top-left corner of the scanner bed. Also give an argument to the --resolution option to specify the scan resolution. Scanner resolutions are given in dpi, or dots per inch.

Common resolution values include 72, 120, 300 and 600 dpi; 72 dpi is the most popular resolution for use on the Web or for just viewing on the screen, and 204 dpi is often used for images that you want to send on a fax machine.

The output is sent to standard output -- so to scan an image to a file, redirect the standard output to a file.

scanimage outputs images in the PNM ("portable anymap") formats, so you'll want to make sure that you have the netpbm package installed as well; this is a useful collection of tools for converting and manipulating these formats, and most Linux systems come with this package installed by default. The PNM formats output by scanimage are as follows:

  • PPM color images
  • PBM black and white images
  • PGM grayscale images

Use the --mode option to specify the format of the output. Follow it with one of the following arguments: "color" for color PPM, "lineart" for black and white PBM, or "gray" for PGM grayscale. Each scanner has a default mode; for most color scanners, the default mode will be "color."

For example, to make a 72 dpi scan of a color image 200 pixels wide and 100 pixels tall, scanned from the device in the above examples and output to a file called scan.ppm, type (on one line):

scanimage -d umax:/dev/sgb 
  --resolution 72 -x 200 -y 100 > scan.ppm

To make a 300 dpi scan of a black and white image 180 pixels wide and 225 pixels tall, scanned from the device in the above examples and output to a file called scan.pbm, type (on one line):

scanimage -d umax:/dev/sgb --resolution 300 
 --mode lineart -x 180 -y 225 > scan.pbm

From here, you can open the file in an image editor such as the GIMP, do command-line image transformations, or use the netpbm tools to manipulate the scanned image.

Next week: about one of the philosophies that Linux is built on.

Michael Stutz was one of the first reporters to cover Linux and the free software movement in the mainstream press.


Read more Living Linux columns.




Tagged Articles

Be the first to post this article to del.icio.us

Recommended for You

  1. Cover of X Power Tools
    X Power Tools
    Print: $39.99
    Ebook: $31.99
  2. Cover of Learning Red Hat Linux
    Learning Red Hat Linux
    Print: $39.95
  3. Cover of Fedora Linux
    Fedora Linux
    Print: $39.99
    Ebook: $31.99
  4. Cover of Absolute OpenBSD
    Absolute OpenBSD
    Print: $39.95

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2010, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com