Skip to content

Instantly share code, notes, and snippets.

@anekos

anekos/kakukaku

Created Feb 23, 2020
Embed
What would you like to do?
kakukaku
#!/bin/bash
set -euC
# set -o pipefail
# exec 5>> /tmp/xmosh/shell-script-debug.out
# BASH_XTRACEFD="5"
# PS4='$LINENO: '
# set -x
if [ "$#" -lt 2 ]
then
echo 'kakukaku <SOURCE_IMAGE> <OUTPUT_GIF>'
exit 1
fi
image="$1"
dest="$2"
wd="$(mktemp -d)"
kaku="${wd}/kaku.png"
function cleanup () {
rm -rf "$wd"
}
trap cleanup EXIT
function calc () {
local ex="$*"
echo "$ex" | bc | sed 's/\..*//'
}
command -v caching || function caching () {
"${@}"
}
wh="$(identify -format '%w %h' "$image")"
w="${wh% *}"
h="${wh#* }"
read -r -a reko < <(
caching aws rekognition detect-faces \
--image-bytes "fileb://${image}" |\
jq --raw-output \
'.FaceDetails[0]|.BoundingBox|[.Left,.Top,.Width,.Height]|join(" ")'
)
fx="$( calc "${reko[0]} * ${w}" )"
fy="$( calc "${reko[1]} * ${h}" )"
fw="$( calc "${reko[2]} * ${w}" )"
fh="$( calc "${reko[3]} * ${h}" )"
d="$( calc "$fh * 0.06" )"
convert "$image" \
\( -clone 0 -crop "${fw}x${fh}+${fx}+${fy}" \) \
\( -clone 0-1 -compose Dst -composite \) \
-delete 0 +swap \
-geometry "+$(( fx ))+$(( fy - d ))" -compose Over -composite \
"$kaku"
convert -delay 5 -loop 0 "$image" "$kaku" "$dest"
command -v chrysoberyl && chrysoberyl @@views 2 @@ "$image" "$dest"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.