songflower

reflow bitmap sheet music to a different paper format
git clone https://a3nm.net/git/songflower/
Log | Files | Refs | README | LICENSE

master.sh (952B)


      1 #!/bin/bash
      2 
      3 # reflow sheet music to new dimensions
      4 
      5 FILE="$1"
      6 WIDTH="$2"
      7 HEIGHT="$3"
      8 OUTFILE="$4"
      9 MARGIN="${5-20}"
     10 DENSITY="${6-250}"
     11 FIXCMD="${7-echo 'not fixing anything'}"
     12 
     13 mkdir -p tmp pages lines chunks outpages
     14 
     15 # convert pdf to one image for each page
     16 TMPDIR=./tmp convert -background white -alpha remove -alpha off \
     17   -quality 100 -density "$DENSITY" "$FILE" pages/page_%04d.png
     18 
     19 # convert each page to lines
     20 ls pages/* | parallel ./splith.py --maxheight=$(($HEIGHT-2*$MARGIN)) '{}' ./lines/
     21 # convert each line to chunks
     22 ls lines/* | parallel ./splitw.py '{}' ./chunks/ $(($WIDTH-2*$MARGIN)) 
     23 
     24 # ad-hoc hook to fix some things
     25 $FIXCMD "$(($WIDTH-2*$MARGIN))"
     26 
     27 # combine chunks into output pages
     28 ./combine.py --hmargin="$MARGIN" --vmargin="$MARGIN" chunks/ outpages/ "$HEIGHT"
     29 
     30 # create output pdf
     31 ls outpages/*.png | while read a ; do echo $a; convert -interpolate bilinear $a ${a%.png}.pdf; done
     32 pdftk outpages/*.pdf cat output "$OUTFILE"
     33