rotate-image
#391
- Author
- winny
- Created
- Sept. 30, 2021, 2:08 a.m.
- Expires
- Never
- Size
- 700 bytes
- Hits
- 233
- Syntax
- Bash
- Private
- ✗ No
#!/usr/bin/env bash
# Interactively rotate a photograph and prompt to save it.
set -eu -o pipefail
tempfile="$(mktemp -t "XXXXXXXXXXXXXXXX.$(basename "$1")")"
trap "rm -f -- $tempfile" EXIT
cp -- "$1" "$tempfile"
while :; do
sxiv -- "$tempfile"
read -n 1 -r -p 'Rotate? (l|r|8|q|s) ' ROTATION
printf '\n'
DIRECTION=0
case $ROTATION in
l*)
DIRECTION=-90
;;
r*)
DIRECTION=90
;;
8*)
DIRECTION=180
;;
q*)
exit
;;
s*)
cp -- "$tempfile" "$1"
exit
esac
convert -rotate "$DIRECTION" -- "$1" "$tempfile"
done