2023-02-24 05:08:31 +00:00
|
|
|
#!/bin/bash
|
2023-03-13 20:35:39 +00:00
|
|
|
|
2023-03-14 15:30:44 +00:00
|
|
|
#######
|
|
|
|
#
|
|
|
|
# Centers a frame of video in a white image container.
|
|
|
|
#
|
|
|
|
######
|
|
|
|
|
2023-03-13 20:35:39 +00:00
|
|
|
source ./common.sh
|
|
|
|
|
2023-03-14 15:30:44 +00:00
|
|
|
# iWidth 323 = oWidth 404
|
|
|
|
# iHeight 242 = oHeight 374
|
|
|
|
# current ratio 1.088
|
|
|
|
# template ratio 1.291
|
2023-02-24 05:08:31 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-03-14 12:22:13 +00:00
|
|
|
if [[ "${2}" != "" ]]; then
|
|
|
|
OUTER=${2}
|
|
|
|
else
|
|
|
|
echo "Please provide outer ratio as second argument"
|
2023-02-24 05:08:31 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${3}" == "" ]]; then
|
2023-03-14 12:22:13 +00:00
|
|
|
echo "Please provide input image as third argument"
|
2023-02-24 05:08:31 +00:00
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
|
2023-03-14 12:22:13 +00:00
|
|
|
if [[ "${4}" == "" ]]; then
|
|
|
|
echo "Please provide output image as fourth argument"
|
|
|
|
exit 4
|
|
|
|
fi
|
|
|
|
|
|
|
|
DIM=$(identify -ping -format '%w %h' "${3}")
|
2023-02-24 05:08:31 +00:00
|
|
|
WIDTH=$(echo ${DIM} | awk '{print $1}')
|
|
|
|
HEIGHT=$(echo ${DIM} | awk '{print $2}')
|
2023-03-14 15:30:44 +00:00
|
|
|
|
2023-02-24 05:08:31 +00:00
|
|
|
R=$(echo "scale=${DIGITS};${HEIGHT}/${WIDTH}" | bc)
|
|
|
|
OW=$(echo "scale=${DIGITS};${DPI}*(404/96)" | bc | awk -F'.' '{print $1}')
|
2023-03-14 12:22:13 +00:00
|
|
|
OH=$(echo "scale=${DIGITS};${OW}*${OUTER}" | bc | awk -F'.' '{print $1}')
|
2023-02-24 05:08:31 +00:00
|
|
|
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)
|
2023-03-14 12:22:13 +00:00
|
|
|
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}"
|
2023-02-24 05:08:31 +00:00
|
|
|
rm -rf "${TMP}"
|
|
|
|
|
2023-03-14 15:30:44 +00:00
|
|
|
echo "Centered in white ${3} -> ${4}"
|
|
|
|
|