#!/bin/bash time=$(date +%Y-%m-%d_%H%M%S) scanimage --resolution 200 -b -x 214.98 -y 294.973 i=1 while [[ -e "out$i.pnm" ]]; do img="out$i.pnm" newname="$(printf "%s_%03d" "$time" "$i")" convert "$img" -normalize -quality 95 "$newname.jpg" && rm "$img" ((i++)) done if [[ $1 = "--pdf" ]]; then convert "${time}"_*.jpg -resize 1500x1500 "${time}.pdf" && rm "${time}"_*.jpg fi