From 10c02667505201b25c72b57c906afd385c4e0c34 Mon Sep 17 00:00:00 2001 From: mmattmcw Date: Tue, 14 Mar 2023 08:22:13 -0400 Subject: [PATCH] Move fourcell scripts into directory. Correctly orient ratio. --- common.sh | 2 +- fourcell.sh | 21 ++++++++-------- fourcell/notes/test_cmd.sh | 1 + .../template_ratio.sh | 0 .../white_fourcell.sh | 25 ++++++++++++------- 5 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 fourcell/notes/test_cmd.sh rename template_ratio.sh => fourcell/template_ratio.sh (100%) rename white_fourcell.sh => fourcell/white_fourcell.sh (65%) diff --git a/common.sh b/common.sh index a3f9e73..caf97c3 100644 --- a/common.sh +++ b/common.sh @@ -70,7 +70,7 @@ get_outer_ratio_frame () { DBX=$(echo "${DX}-${BX}" | bc) ACY=$(echo "${AY}-${CY}" | bc) DBY=$(echo "${DY}-${BY}" | bc) - echo "scale=4;((${ACY}+${DBY})/2) / ((${ACX}+${DBX})/2)" | bc + echo "scale=4;((${ACX}+${DBX})/2) / ((${ACY}+${DBY})/2)" | bc } get_outer_ratio () { diff --git a/fourcell.sh b/fourcell.sh index f702a3c..fc65b64 100644 --- a/fourcell.sh +++ b/fourcell.sh @@ -36,10 +36,10 @@ else fi fi -tiff_name () { +img_name () { filename=$(basename "${1}") filename="${filename%.*}" - echo "${filename}.tif" + echo "${filename}.png" } echo "Using frames in ${OUTPUT}..." @@ -48,6 +48,7 @@ W=$(cat "${1}" | jq -r ".width") H=$(cat "${1}" | jq -r ".height") DPI=$(echo "${W}/8.5" | bc) FRAMES=$(mktemp) +RATIO=$(bash fourcell/template_ratio.sh "${1}") echo "DPI: $DPI" @@ -64,29 +65,29 @@ for ((i=0;i<${PAGES};++i)); do f4=$(sed -n "$(((i*4)+4))p" < "${FRAMES}") args="" if [[ "${f1}" != "" ]]; then - name=$(tiff_name "${f1}") + name=$(img_name "${f1}") dest="${TMP}/${name}" - bash white_fourcell.sh $DPI "${f1}" "${dest}" + bash fourcell/white_fourcell.sh $DPI $RATIO "${f1}" "${dest}" args="${args} ${dest}" else continue fi if [[ "${f2}" != "" ]]; then - name=$(tiff_name "${f2}") + name=$(img_name "${f2}") dest="${TMP}/${name}" - bash white_fourcell.sh $DPI "${f2}" "${dest}" + bash fourcell/white_fourcell.sh $DPI $RATIO "${f2}" "${dest}" args="${args} ${dest}" fi if [[ "${f3}" != "" ]]; then - name=$(tiff_name "${f3}") + name=$(img_name "${f3}") dest="${TMP}/${name}" - bash white_fourcell.sh $DPI "${f3}" "${dest}" + bash fourcell/white_fourcell.sh $DPI $RATIO "${f3}" "${dest}" args="${args} ${dest}" fi if [[ "${f4}" != "" ]]; then - name=$(tiff_name "${f4}") + name=$(img_name "${f4}") dest="${TMP}/${name}" - bash white_fourcell.sh $DPI "${f4}" "${dest}" + bash fourcell/white_fourcell.sh $DPI $RATIO "${f4}" "${dest}" args="${args} ${dest}" fi bash apply_image.sh ${3}/page_$i.tiff "${1}" ${args} diff --git a/fourcell/notes/test_cmd.sh b/fourcell/notes/test_cmd.sh new file mode 100644 index 0000000..ae5bbb0 --- /dev/null +++ b/fourcell/notes/test_cmd.sh @@ -0,0 +1 @@ +bash fourcell.sh ~/Desktop/running/shot1-scans/image-3-normal.png.template.json ~/Desktop/countdown1/ ~/Desktop/pages/ \ No newline at end of file diff --git a/template_ratio.sh b/fourcell/template_ratio.sh similarity index 100% rename from template_ratio.sh rename to fourcell/template_ratio.sh diff --git a/white_fourcell.sh b/fourcell/white_fourcell.sh similarity index 65% rename from white_fourcell.sh rename to fourcell/white_fourcell.sh index 45af295..3ab95f0 100644 --- a/white_fourcell.sh +++ b/fourcell/white_fourcell.sh @@ -22,29 +22,36 @@ else exit 1 fi -if [[ "${2}" == "" ]]; then - echo "Please provide input image as second argument" +if [[ "${2}" != "" ]]; then + OUTER=${2} +else + echo "Please provide outer ratio as second argument" exit 2 fi if [[ "${3}" == "" ]]; then - echo "Please provide output image as third argument" + echo "Please provide input image as third argument" exit 3 fi -DIM=$(identify -ping -format '%w %h' "${2}") +if [[ "${4}" == "" ]]; then + echo "Please provide output image as fourth argument" + exit 4 +fi + +DIM=$(identify -ping -format '%w %h' "${3}") 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}') -OH=$(echo "scale=${DIGITS};${DPI}*(374/96)" | bc | awk -F'.' '{print $1}') +OH=$(echo "scale=${DIGITS};${OW}*${OUTER}" | 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}') TMP=$(mktemp -d) -convert -size ${OW}x${OH} -colorspace sRGB xc:#FFFFFF "${TMP}/white.png" -convert "${2}" -resize ${IW}x${IH} "${TMP}/resize.tif" -composite -gravity Center -colorspace sRGB "${TMP}/resize.tif" "${TMP}/white.png" "${3}" +convert -size ${OW}x${OH} -colorspace sRGB xc:#FFFFFF "${TMP}/white.tif" +convert "${3}" -resize ${IW}x${IH} "${TMP}/resize.tif" +composite -gravity Center -colorspace sRGB "${TMP}/resize.tif" "${TMP}/white.tif" "${4}" rm -rf "${TMP}" -echo "Centered in white ${2} -> ${3}" \ No newline at end of file +echo "Centered in white ${3} -> ${4}" \ No newline at end of file