Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Open all image files in feh before working on them, to rotate them to proper orientation by hand
- feh --recursive --edit --scale-down --auto-zoom --geometry 1280x740 "$1"
- cd "$1"
- # Iterate over folders, each of which contains files from one pupil
- for FOLDER in "$1"/*/; do
- # Get the pupil's name
- echo "$FOLDER" >> "$1"/log.log
- cd "$FOLDER"
- NAME=$(basename "$FOLDER" | cut -f1 -d "_")
- echo $NAME >> "$1"/log.log
- # If the pupil submitted PDFs, join them; if the result is larger than 5MB, compress it with ps2pdf
- if [[ $(ls) == *"pdf"* ]]; then
- pdfunite *.pdf "$NAME".pdf
- if [ $(stat --printf="%s" "$NAME".pdf) -gt "5000000" ]; then
- echo "pdf too large, compressing" >> "$1"/log.log
- ps2pdf "$NAME".pdf _compressed_"$NAME".pdf
- mv _compressed_"$NAME".pdf "$NAME".pdf
- fi
- mv "$NAME".pdf ../"$NAME".pdf
- else
- # If the pupil submitted images, iterate over them, remove the orientation EXIF data to preserve the manually set orientation, then compress the individual image files, if they are larger than 1,5MB; then merge the image files to a PDF
- for filename in ./*; do
- exiv2 rm "filename"
- if [ $(stat --printf="%s" "$filename") -gt "1500000" ]; then
- echo "image $filename too large, compressing" >> "$1"/log.log
- name=$(basename "$filename" | awk -F'.' 'sub(FS $NF,x)')
- echo "$name" >> "$1"/log.log
- magick "$filename" -interlace Plane -gaussian-blur 0.05 -quality 85% _compressed_"$name".jpg
- rm "$filename"
- fi
- done
- convert * ../"$NAME".pdf
- fi
- # Set the size to A4 such that the pen thickness in Xournal++ is suiting
- gs -sDEVICE=pdfwrite -sPAPERSIZE=a4 -dPDFFitPage -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -sOutputFile=../out.pdf ../"$NAME".pdf
- # Set the DPI to a low value such that the pixel dimensions are not too large and Xournal++ won't hang
- convert -units PixelsPerInch -density 120 ../out.pdf ../"$NAME".pdf
- rm ../out.pdf
- done
Advertisement
Add Comment
Please, Sign In to add comment