IgnorantGuru's Blog

Linux software, news, and tips

Script: scanpic


Download Links: downloadbrowseauthenticate
Description: Scans pic of specified size to jpg file
Recommended For: Linux
Requires: sane sane-utils imagemagick
License: GNU GPL v3     * SEE DISCLAIMER *
Related: repic webpics
Feedback: commentsissues


Scanpic allows you to scan images of a specified size from the command line without use of a GUI and without needing to crop the image afterward. I wrote this script when I had hundreds of old pics of various sizes to scan, and I didn’t want to have to crop them all individually.

scanpic --help

Scans pic to jpg file on scanner device                                 
Requires: sane sane-utils imagemagick                                   
Usage:   scanpic [OPTIONS] OUTPUTFILENAME.JPG                           
Example: scanpic --opt 4x6v,gray --size 1280x1280 myscan.jpg            
         scans 4x6 vertical grayscale print to 1280x1280(max) jpeg      
   --opt <option>,<option>,...   image options (see below)              
   --size <width>x<height>       max final size (pixels) (overrides opt)
                                 [default 2560x2560]
   --quality <0...100>           jpeg quality (overrides opt)
                                 [default 90]
   --dims <width>x<height>       scan size (mm) (overrides opt)
                                 [default full]
   --offset <width>x<height>     offset (mm) (overrides opt)
                                 [default 0x0]
   --res <dpi>                   resolution dpi (overrides opt)
                                 [default 600]
   --rotate <degrees>            rotation (overrides opt) [default 0]
   --bright <-50...50%>          scan brightness (overrides opt)
   --contrast <-50...50%>        scan contrast (overrides opt)
   --device DEVICENAME           scanner device (see: scanimage --list)
                                 [default  ]
opt arguments:
   bw         color mode "Black & White"
   gray       color mode "True Gray"
   col        color mode "24bit Color"
   page       scan size 8.5x11" gray - no offset
   walletv    scan size 44x64mm vertical
   pocketv    scan size 60x85mm vertical
   pocketh    scan size 85x60mm horiz
   3.5x5v     scan size 3.5x5" vertical
   3.5x5h     scan size 3.5x5" horiz
   3.5x5sv    scan size 3.5x5" (slightly smaller than 5") vertical
   3.5x5sh    scan size 3.5x5" (slightly smaller than 5") horiz
   4.25x3.5h  scan size 4.25x3.5" horiz
   4x6v       scan size 4x6" vertical
   4x6h       scan size 4x6" horiz
   4x10       scan size 4x10" (place vertical)
   5x7        vscan size 5x7" vertical
   5x7h       scan size 5x7" horiz
   8x10v      scan size 8x10" vertical
   8x10h      scan size 8x10" horiz (place vertical)
   polaroidh  Polaroid horiz
Note: Place --opt before other options.

By default, scanpic will scan the entire size of the scanbed. If a pic size is specified with “–opt” or with “–dims”, it will can only the region specified, which speeds up scanning.


# scan a grayscale 8.5x11" page
scanpic --opt page myscan.jpg

# scan a 24bit color 8.5x11" page
scanpic --opt page,col myscan.jpg

# scan a B&W 8.5x11" page, rotate 90 degrees, and reduce to 1024x768
scanpic --opt page,bw --rotate 90 --size 1024x768 myscan.jpg

# scan a 3.5x5inch vertical color photo at 300dpi
scanpic --opt 3.5x5v,col --res 300 myscan.jpg

By default, scanpic uses very high quality settings for the scan, which produces a relatively large file, but these can be reduced using the command line arguments, or by editing the User Defaults section at the top of the script.

scanpic will attempt to determine the device name of your scanner. You can also set the device name in the User Defaults section (which will also speed up scanning). You can lookup the scanner device using:

scanimage --list

device `brother2:bus4;dev1' is a Brother MFC-7420 USB scanner

In the above example, you would use “brother2” as the device name.

Some scanners will not scan to the very edge of the scanbed. To compensate for this, you can shift the photo away from the very corner and specify an offset to scanpic. On my Brother MFC-7420, I taped an L-shaped piece of cardboard into the corner of the scanbed to create an offset, then determined that the offset I needed in scanpic was 12×4.5 (mm). If you notice the photo is shifted out of place, you may need to use a similar method to move the photo away from the corner of the scanbed, then scan a few times experimenting with offsets. Once you get it calibrated, scanning almost perfectly cropped photos is very fast.

Installation Instructions

Follow the standard Script Installation Instructions.

Before running scanpic, install required packages using your package manager, or on *ubuntu:

sudo apt-get install sane sane-utils imagemagick

No comments yet.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: