2023-02-25 02:27:08 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-02-25 03:28:01 +00:00
|
|
|
#set -e
|
|
|
|
|
2023-02-25 02:27:08 +00:00
|
|
|
if [[ "${1}" == "" ]]; then
|
2023-03-13 20:35:39 +00:00
|
|
|
echo "Please provide a template JSON"
|
2023-02-25 02:27:08 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${2}" == "" ]]; then
|
|
|
|
echo "Please provide one video or directory of images"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2023-03-04 23:51:22 +00:00
|
|
|
if [[ "${3}" == "" ]]; then
|
|
|
|
echo "Please an output directory for pages"
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "${3}" ]; then
|
|
|
|
echo "${3} output directory does not exist"
|
|
|
|
exit 4
|
|
|
|
fi
|
|
|
|
|
2023-02-25 03:28:01 +00:00
|
|
|
if [ -f "${2}" ]; then
|
|
|
|
echo "Exporting frames from ${2}..."
|
2023-02-25 02:27:08 +00:00
|
|
|
OUTPUT=$(mktemp -d)
|
2023-02-25 03:28:01 +00:00
|
|
|
ffmpeg -y -re -i "${2}" \
|
2023-02-25 02:27:08 +00:00
|
|
|
-q:v 1 -qmin 1 -qmax 1 \
|
|
|
|
"${OUTPUT}/frame_%06d.tif"
|
|
|
|
else
|
2023-02-25 03:28:01 +00:00
|
|
|
if [ -d "${2}" ]; then
|
|
|
|
OUTPUT="${2}"
|
|
|
|
else
|
|
|
|
echo "Argument ${2} is neither video nor directory"
|
|
|
|
exit 43
|
|
|
|
fi
|
2023-02-25 02:27:08 +00:00
|
|
|
fi
|
|
|
|
|
2023-03-14 12:22:13 +00:00
|
|
|
img_name () {
|
2023-02-25 03:28:01 +00:00
|
|
|
filename=$(basename "${1}")
|
|
|
|
filename="${filename%.*}"
|
2023-03-14 12:22:13 +00:00
|
|
|
echo "${filename}.png"
|
2023-02-25 03:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "Using frames in ${OUTPUT}..."
|
2023-03-19 01:27:09 +00:00
|
|
|
NAME=$(basename "${OUTPUT}")
|
2023-03-14 15:30:44 +00:00
|
|
|
DIGITS=6
|
|
|
|
SCALE=$(echo "scale=$DIGITS; 323/404" | bc)
|
|
|
|
OUTER=$(echo "scale=$DIGITS; 374/404" | bc)
|
|
|
|
|
2023-02-25 03:28:01 +00:00
|
|
|
W=$(cat "${1}" | jq -r ".width")
|
|
|
|
H=$(cat "${1}" | jq -r ".height")
|
|
|
|
DPI=$(echo "${W}/8.5" | bc)
|
|
|
|
FRAMES=$(mktemp)
|
2023-03-14 12:22:13 +00:00
|
|
|
RATIO=$(bash fourcell/template_ratio.sh "${1}")
|
2023-03-14 15:30:44 +00:00
|
|
|
TMP=$(mktemp -d)
|
|
|
|
|
|
|
|
echo "DPI: ${DPI}"
|
2023-02-25 03:28:01 +00:00
|
|
|
|
2023-03-14 15:30:44 +00:00
|
|
|
ONEFRAME=$(ls -1 "${OUTPUT}"*.{jpg,jpeg,JPG,JPG,png,PNG,gif,GIF,tif,tiff,TIF,TIFF} 2> /dev/null | head -n1)
|
|
|
|
DIM=$(identify -ping -format '%w %h' "${ONEFRAME}")
|
|
|
|
WIDTH=$(echo ${DIM} | awk '{print $1}')
|
|
|
|
HEIGHT=$(echo ${DIM} | awk '{print $2}')
|
|
|
|
R=$(echo "scale=${DIGITS};${HEIGHT}/${WIDTH}" | bc)
|
|
|
|
OW=$(echo "scale=${DIGITS};${DPI}*(404/96)" | bc | awk -F'.' '{print $1}')
|
|
|
|
IW=$(echo "scale=${DIGITS};${OW}*${SCALE}" | bc | awk -F'.' '{print $1}')
|
|
|
|
IH=$(echo "scale=${DIGITS};${IW}*${R}" | bc | awk -F'.' '{print $1}')
|
2023-02-25 03:28:01 +00:00
|
|
|
|
2023-03-14 15:30:44 +00:00
|
|
|
GUIDE="${TMP}/guide_$(date +%s).png"
|
|
|
|
bash fourcell_guide.sh --dpi ${DPI} --dimensions "${IW}x${IH}" "${GUIDE}"
|
|
|
|
echo "${GUIDE}" > "${FRAMES}"
|
|
|
|
|
|
|
|
ls -1 "${OUTPUT}"*.{jpg,jpeg,JPG,JPG,png,PNG,gif,GIF,tif,tiff,TIF,TIFF} >> "${FRAMES}" 2> /dev/null
|
2023-02-25 03:28:01 +00:00
|
|
|
FC=$(wc -l < "${FRAMES}")
|
|
|
|
PAGES=$(echo "(${FC}/4)+1" | bc)
|
|
|
|
|
|
|
|
for ((i=0;i<${PAGES};++i)); do
|
|
|
|
f1=$(sed -n "$(((i*4)+1))p" < "${FRAMES}")
|
|
|
|
f2=$(sed -n "$(((i*4)+2))p" < "${FRAMES}")
|
|
|
|
f3=$(sed -n "$(((i*4)+3))p" < "${FRAMES}")
|
|
|
|
f4=$(sed -n "$(((i*4)+4))p" < "${FRAMES}")
|
|
|
|
args=""
|
|
|
|
if [[ "${f1}" != "" ]]; then
|
2023-03-14 12:22:13 +00:00
|
|
|
name=$(img_name "${f1}")
|
2023-02-25 03:28:01 +00:00
|
|
|
dest="${TMP}/${name}"
|
2023-03-14 12:22:13 +00:00
|
|
|
bash fourcell/white_fourcell.sh $DPI $RATIO "${f1}" "${dest}"
|
2023-02-25 03:28:01 +00:00
|
|
|
args="${args} ${dest}"
|
|
|
|
else
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if [[ "${f2}" != "" ]]; then
|
2023-03-14 12:22:13 +00:00
|
|
|
name=$(img_name "${f2}")
|
2023-02-25 03:28:01 +00:00
|
|
|
dest="${TMP}/${name}"
|
2023-03-14 12:22:13 +00:00
|
|
|
bash fourcell/white_fourcell.sh $DPI $RATIO "${f2}" "${dest}"
|
2023-02-25 03:28:01 +00:00
|
|
|
args="${args} ${dest}"
|
|
|
|
fi
|
|
|
|
if [[ "${f3}" != "" ]]; then
|
2023-03-14 12:22:13 +00:00
|
|
|
name=$(img_name "${f3}")
|
2023-02-25 03:28:01 +00:00
|
|
|
dest="${TMP}/${name}"
|
2023-03-14 12:22:13 +00:00
|
|
|
bash fourcell/white_fourcell.sh $DPI $RATIO "${f3}" "${dest}"
|
2023-02-25 03:28:01 +00:00
|
|
|
args="${args} ${dest}"
|
|
|
|
fi
|
|
|
|
if [[ "${f4}" != "" ]]; then
|
2023-03-14 12:22:13 +00:00
|
|
|
name=$(img_name "${f4}")
|
2023-02-25 03:28:01 +00:00
|
|
|
dest="${TMP}/${name}"
|
2023-03-14 12:22:13 +00:00
|
|
|
bash fourcell/white_fourcell.sh $DPI $RATIO "${f4}" "${dest}"
|
2023-02-25 03:28:01 +00:00
|
|
|
args="${args} ${dest}"
|
|
|
|
fi
|
2023-03-19 01:27:09 +00:00
|
|
|
bash apply_image.sh ${NAME} ${3}/${NAME}_$i.tiff "${1}" ${args}
|
2023-02-25 03:28:01 +00:00
|
|
|
done
|
2023-02-25 02:27:08 +00:00
|
|
|
|
2023-03-19 01:27:09 +00:00
|
|
|
echo "Wrote ${3}/${NAME}_$i.tiff"
|
2023-03-04 23:51:22 +00:00
|
|
|
|
2023-02-25 03:28:01 +00:00
|
|
|
# x determine dpi
|
|
|
|
# convert frame to white_fourcell
|
2023-02-25 02:27:08 +00:00
|
|
|
|
2023-02-25 03:28:01 +00:00
|
|
|
rm "${FRAMES}"
|
|
|
|
rm -rf "${TMP}"
|