# Extract the framing stuff:
tfile_ot="${temp}_ot.png"
ofile_ot="${dir}/ot.png"
echo "creating ${ofile_ot} ..." 1>&2
convert ${ifile} \
    -set colorspace LinearGray \
    \( ${ifile} -colorspace Gray -threshold '0%' -fill black -draw "rectangle ${p1} ${p2}" \) \
    -compose multiply \
    -composite \
    ${rotcmd[@]} \
    -gamma 1.0 \
    -resize '25%' \
    -colorspace LinearGray \
    PNG48:${tfile_ot}
pngcrush ${tfile_ot} ${ofile_ot}
  

#
# Also extracts from "${ifile}" an image "${dir}/ruler.png" of the 
# measuring ruler that was placed next to the page when it was photographed.

# Extracting the ruler image:
ofile_ru=${dir}/ruler.png
echo "creating ${ofile_ru} ..." 1>&2
convert ${ifile} \
    -set colorspace LinearGray \
    -crop "${ruler_crop}" \
    -resize '25%' \
    ${rotcmd[@]} \
    -colorspace Gray \
    PNG:${ofile_ru}


# while [[ ${maxval} -lt ${real_maxval[0]} ]]; do
#   maxval=$(( 3 * ( ${maxval} + 1 ) / 2 ))
# done
# echo "  using maxval = ${maxval}" 1>&2

