いよいよ仕上げです
操作ページは簡単なものにしていますが、もっと作りこんでもいいなーと思っています
コードは参考程度にどうぞ
raspiscan.phpとindex.htmlの作成
以下のファイルを/usr/share/nginx/www/raspiscan/下に置く
raspiscan.php
if($_GET["duplex"] != null) {
$duplex = ($_GET["duplex"] == "0")? "ADF Front" : "ADF Duplex";
}
if($_GET["color"] != null) {
$color = ($_GET["color"] == "0")? "Gray" : "Color";
}
if($_GET["location"] != null) {
if($_GET["location"] == "ne-ne") {
$location = "ne-ne";
} else if($_GET["location"] == "chibi") {
$location = "chibi";
} else {
$location = "other";
}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head lang="ja">
<meta charset="UTF-8">
<title>おてがみポスト</title>
</head>
<body>
<?php $result = shell_exec("sudo /home/raspiscan/raspiscan.sh \"$duplex\" $color $location"); ?>
<p><?php echo $result; ?></p>
<p><a href="index.html">もどる</a></p>
</body>
index.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head lang="ja">
<meta charset="UTF-8">
<title>おてがみポスト</title>
</head>
<body>
<h1>えらんでね</h1>
<span id="test"></span>
<div id="main">
<form action="raspiscan.php" method="get">
<ul id="selectDuplexPrint">
<li><input type="radio" name="duplex" value="0" checked="checked">かためん</li>
<li><input type="radio" name="duplex" value="1">りょうめん</li>
</ul>
<ul id="selectColorMode">
<li><input type="radio" name="color" value="0" checked="checked">しろくろ</li>
<li><input type="radio" name="color" value="1">カラー</li>
</ul>
<ul id="selectSaveLocation">
<li><input type="radio" name="location" value="ne-ne">おねえちゃん</li>
<li><input type="radio" name="location" value="chibi">ちび</li>
</ul>
<input type="submit" value="スキャン">
</form>
</div>
</body>
</html>
raspiscan.shを書き換える
/home/raspiscan/raspiscan.shを以下のように書き換える
raspiscan.sh
#!/bin/sh
SOURCE=$1
MODE=$2
LOCATION=$3
TMPDIR=/home/raspiscan/tmp
FILENAME=scan-`date "+%Y%m%d-%H%M%S"`
/bin/mkdir -p $TMPDIR
cd $TMPDIR
/usr/bin/scanimage --batch --source "$SOURCE" --mode $MODE --resolution=190 --y-resolution=190 --format=tiff
convert -compress JPEG -quality 85 -adjoin `ls -1 *.tif | sort -t t -k 2 -n` out.pdf
dropbox_uploader.sh upload /home/raspiscan/tmp/out.pdf $LOCATION/$FILENAME.pdf
rm -Rf $TMPDIR
参考サイト:
SANEのコマンドオプションなど
SANE Scanner Access Now Easy