From ff910b9dae46b3bf84f489ce0f9bd2cf432fd119 Mon Sep 17 00:00:00 2001 From: mmattmcw Date: Fri, 24 Feb 2023 00:08:31 -0500 Subject: [PATCH] Scale images for the fourcell process --- scale_img.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 scale_img.sh diff --git a/scale_img.sh b/scale_img.sh new file mode 100644 index 0000000..1d499eb --- /dev/null +++ b/scale_img.sh @@ -0,0 +1,42 @@ +#!/bin/bash +#iWidth 323 = oWidth 404 +#iHeight 242 = oHeight 374 + +DIGITS=6 +SCALE=$(echo "scale=$DIGITS; 323/404" | bc) +OUTER=$(echo "scale=$DIGITS; 374/404" | bc) +RATIO=$(echo "scale=$DIGITS; 242/323" | bc) + +if [[ "${1}" != "" ]]; then + DPI=${1} +else + echo "Please provide DPI as first argument" + exit 1 +fi + +if [[ "${2}" == "" ]]; then + echo "Please provide input image as second argument" + exit 2 +fi + +if [[ "${3}" == "" ]]; then + echo "Please provide output image as third argument" + exit 3 +fi + +DIM=$(identify -ping -format '%w %h' "${2}") +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}') +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} xc:#FFFFFF "${TMP}/white.png" +convert "${2}" -resize ${IW}x${IH} "${TMP}/resize.tif" +composite -gravity Center "${TMP}/resize.tif" "${TMP}/white.png" "${3}" +rm -rf "${TMP}" + +echo "Centered in white ${2} -> ${3}" \ No newline at end of file