Created
February 23, 2020 14:51
-
-
Save anekos/60325839781306693614db26d7c87a8f to your computer and use it in GitHub Desktop.
kakukaku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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