File indexing completed on 2024-05-19 08:25:14

0001 #!/bin/bash
0002 
0003 # Skanlite D-Bus example script.
0004 # this script listens for D-Bus imageSaved signal from Skanlite then
0005 # postprocesses scanned image with help of gimp application,
0006 # prints it and remove file. (the last two commands are disabled by default)
0007 
0008 # gimp provides much more powerful tools for image processing
0009 # in particulary for color balance correction
0010 # in this example we decreasing Highlights (brightest pixels) gamma's red by 18
0011 
0012 interface=org.kde.skanlite
0013 sender=org.kde.skanlite
0014 member=imageSaved
0015 
0016 # listen for imageSaved D-Bus events,
0017 # each time we enter the loop, we just got an event
0018 
0019 dbus-monitor --profile "type='signal',sender='$sender',interface='$interface',member='$member'" --monitor |
0020 while read -r line; do
0021 
0022 if [[ $line == *"member=imageSaved"* ]]; then
0023    read -r line;
0024 
0025    if [[ $line == *"string \""*"\"" ]]; then
0026 
0027       [[ $line =~ string[[:space:]]\"(.*)\" ]]
0028 
0029       # Here you can apply some additional filters. For example filter out
0030       # grayscale scans with help of identify (from imagemagick package)
0031       # like, identify -verbose $filename | grep 'Type: TrueColor'
0032 
0033       filename=${BASH_REMATCH[1]}
0034       printf "Processing scan: $filename\n"
0035       gimp -i -b '(let* ((filename "'$filename'")
0036                          (image (car (gimp-file-load RUN-NONINTERACTIVE
0037                                                           filename filename)))
0038                          (drawable (car (gimp-image-get-active-layer image))))
0039                         (gimp-color-balance
0040                                                          drawable 2 1 -18 0 0) ; Change these parameters to adjust color balanse
0041                         (gimp-file-save RUN-NONINTERACTIVE
0042                                              image drawable filename filename)
0043                         (gimp-image-delete image))' \
0044               -b '(gimp-quit 0)'
0045 
0046        #printf "Printing: $filename\n"
0047        #lp $filename # Send to default printer. Configure this command if needed
0048 
0049        #rm $filename # Remove file
0050     fi
0051   fi
0052 done