2024-08-19 10:38:46 +00:00
self : with self ; ''
2024-04-18 10:51:43 +00:00
echo " $ @ "
DUPLEX = , Duplex
removeempty = " t r u e "
[ [ $ 1 == " - s " ] ] && {
DUPLEX = " "
removeempty = false
shift
}
[ [ $ 1 == " - a " ] ] && {
DUPLEX = , Duplex
removeempty = " t r u e "
shift
}
[ [ $ 1 == " - d " ] ] && {
DUPLEX = , Duplex
shift
}
cleanup ( ) {
echo finalizing pdf file .
$ { img2pdf } /bin/img2pdf - - pdfa - - output /tmp/scan2paperless_ $ $ . pdf /tmp/scan2paperless_ $ $ _ * . png && \
rm - f /tmp/scan2paperless_ $ $ _ * . png
scp /tmp/scan2paperless_ $ $ . pdf pub-solar @ paperless.faenix.eu:~/.local/share/scandir \
&& rm - f /tmp/scan2paperless_ $ $ * \
|| echo upload failed , retaining file /tmp/scan2paperless_ $ $ . pdf > & 2
}
trap ' cleanup ; exit 1 ' EXIT
$ { sane-backends } /bin/scanimage - - device ' brother5:bus1 ; dev5' - - format = png - - resolution 300 - - batch = /tmp/scan2paperless_ $ $ _ % d . png - - AutoDeskew = yes - - batch-start = 10 - - source = " A u t o m a t i c D o c u m e n t F e e d e r ( l e f t a l i g n e d ' ' ${ DUPLEX } ) " - x 210 - y 297
if $ removeempty
then
threshold = 99
images = ( )
values = ( )
for f in /tmp/scan2paperless_ $ $ _ * . png
do
images [ '' ${ #images[@]}]=$f
values [ '' ${ #values[@]}]=$(${imagemagick}/bin/convert "$f" -fuzz 02% -fill black +opaque white -fill white -opaque white -format "%[fx:100*mean]" info:)
done
for ( ( i = 0 ; i < '' ${ #images[@]};i++))
do
if [ [ $ ( echo " ' ' ${ values [ i ] } > $ t h r e s h o l d " | $ { bc } /bin/bc - l ) == " 1 " ] ]
then
# bc will output 1 if the comparison is true, 0 otherwise
echo image " ' ' ${ images [ i ] } " was found to be mostly white , removing .
rm " ' ' ${ images [ i ] } "
fi
done
fi
''