Skip to content

Instantly share code, notes, and snippets.

@christf
Created January 11, 2017 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christf/feef77877289483485c846e8e03d0d3a to your computer and use it in GitHub Desktop.
Save christf/feef77877289483485c846e8e03d0d3a to your computer and use it in GitHub Desktop.
#!/bin/bash
# this is working under the assumption that oid are 4 digit only.
odir=oid
bdir=background
adir=audio
cdir=codes
yamlfile=$1
density=600
[ $# -lt 1 ] && {
echo syntax: $0 yamlfile
exit 2
}
rm -rf oid
mkdir oid
cd oid
tttool --pixel-size 2 --dpi 600 oid-codes "../${yamlfile}"
cd ..
tttool assemble "${yamlfile}"
preprocess() {
afile="$1"
bfile="$2"
ofile="$3"
oid="$4"
temp=temp1_$$.png
# obtain size from oid-file
# resize background to size of oid-file
# brighten background by 20%
convert "$bfile" -density $density -resize "$size" -gravity center -extent "$size" -background white -brightness-contrast 20x0 "$temp"
# place oid-overlay
composite -gravity center "$ofile" "$temp" "$cdir/${ofile##*/}"
rm -f "$temp"
}
while IFS= read -r -d '' ofile
do
temp=${ofile##*-}
oid=${temp:0:4}
[[ $temp == START.png ]] && oid=START
temp=$(grep "$oid" "$yamlfile" -A 1|tail -n1|cut -d"(" -f2|cut -d")" -f1)
[[ $oid == START ]] && temp=START
bfile="$bdir/$temp.*"
afile="$adir/$temp.*"
if [ -f $bfile ]
then
[[ -z $size ]] && size=$(identify "$ofile" |cut -d" " -f3)
preprocess $afile $bfile $ofile $oid
else
echo file $bfile does not exist
fi
done < <(find "$odir" -type f -name "*.png" -print0)
# generate a5 layout pages
# A4 hat ein Format von 297x200mm
# A5 hat also 210x148mm
# Seitenränder: 20mm ringsherum. Dadurch ergibt sich ein bedruckbarer bereich
# von 170x108mm
#
# 1 inch = 25.4mm
# bei 600dpi entsprechen 720 px 30.48mm. Es passen also 5 Bilder untereinander
# und 3 nebeneinander auf A5 Auf jeder Seite ist das Erste Bild das Startbild,
# sodass 14 Bilder aus den Soundfiles genutzt werden können.
#
# Dabei können noch Ränder von 20px zwischen den Bildern eingebaut werden.
#
cat >${yamlfile}.tex <<EOF
\documentclass[a5paper,11pt]{scrreprt}
\usepackage[bottom=1cm,top=2cm,left=2cm,right=2cm]{geometry}
\author{Christof Schulze}
\date{\today}
\usepackage{graphicx}
\begin{document}
\centering
EOF
shopt -s extglob
files=( "$cdir"/oid-+([0-9])-+([0-9]).png )
startbild=$cdir/oid-+([0-9])-START.png
pages=0
i=0
while [ $i -lt ${#files[@]} ]
do
((pages+=1))
thispages=( )
for ((i=14*(pages-1);i<14*pages;i++))
do
thispages[${#thispages[@]}]=${files[i]}
done
montage $startbild ${thispages[@]} -geometry ">+20+20" -tile 3x5 -density $density out-page_${pages}.png
echo "\includegraphics[resolution=600]{out-page_${pages}.png} \\\\" >>${yamlfile}.tex
done
echo "\end{document}" >>${yamlfile}.tex
pdflatex "${yamlfile}.tex"
rm "${yamlfile}.log"
rm "${yamlfile}.aux"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment