Skip to content

Instantly share code, notes, and snippets.

@pechfunk
Created April 27, 2018 20:06
Show Gist options
  • Save pechfunk/63ac270acf803bfaffa9ae03fe5747e5 to your computer and use it in GitHub Desktop.
Save pechfunk/63ac270acf803bfaffa9ae03fe5747e5 to your computer and use it in GitHub Desktop.
Example pyinsane2 program to scan using duplex ADF
import sys
import pyinsane2
pyinsane2.init()
try:
devices = pyinsane2.get_devices()
assert(len(devices) > 0)
device = devices[0]
print("I'm going to use the following scanner: %s" % (str(device)))
try:
pyinsane2.set_scanner_opt(device, 'source', ['ADF Duplex', 'ADF', 'Feeder'])
except pyinsane2.PyinsaneException as e:
print("No document feeder found", e)
sys.exit(1)
# Beware: Some scanners have "Lineart" or "Gray" as default mode
# better set the mode everytime
pyinsane2.set_scanner_opt(device, 'mode', ['Color'])
# Beware: by default, some scanners only scan part of the area
# they could scan.
pyinsane2.maximize_scan_area(device)
scan_session = device.scan(multiple=True)
try:
while True:
try:
scan_session.scan.read()
except EOFError:
print ("Got a page ! (current number of pages read: %d)"
% (len(scan_session.images)))
except StopIteration:
print("Document feeder is now empty. Got %d pages"
% len(scan_session.images))
for idx in range(0, len(scan_session.images)):
image = scan_session.images[idx]
image.save("wuff%d.png"%idx)
finally:
pyinsane2.exit()
@yudisaefulrizal
Copy link

Semoga kau masuk surga, terimakasih banyak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment