triggered.sh

nicolaw 7th February 2020 at 12:15pm
Avatars CodeSnippets
#!/usr/bin/env bash
# vim:ts=2:sw=2:tw=79

set -Eeuo pipefail

trap 'declare rc=$?;
      >&2 echo "Unexpected error executing $BASH_COMMAND at ${BASH_SOURCE[0]} line $LINENO"; exit $rc' ERR

main () {
  declare in="${1:-image.png}"
  declare smol="${in%.*}-smol.gif"
  declare out="${in%.*}-triggered.gif"
  declare geometry=48x48 delay=3

  convert -sample "$geometry" "$in" "$smol"
  convert -loop 0 -delay "$delay" -size "$geometry" "$smol" \
    -page "-2-0" -dispose "Background" "$smol" \
    -page "+2-0" -dispose "Background" "$smol" \
    -page "-3+1" -dispose "Background" "$smol" \
    "$out"

  echo "$out"
}

main "$@"