-
Notifications
You must be signed in to change notification settings - Fork 0
/
autocrop
executable file
·37 lines (29 loc) · 968 Bytes
/
autocrop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env fish
# autocrop - Automatically trim blank edges of an image.
# Copies the original image to /tmp first in case you want to restore it later.
# settings:
# default fuzz percent
set fuzz 30
# code:
set -- script "$(basename (status filename))"
argparse -n "$script" 'h/help' 'f/fuzz=' -- $argv
if set -q _flag_h
echo "$script - Automatically trim blank edges of an image."
echo "Usage: $script [arguments]"
echo
echo " -h/--help - Print help and exit."
echo " -f/--fuzz - Set \"fuzz\"; the distance that colors within are considered equal (default: $fuzz%)."
exit
end
if set -q _flag_f
set fuzz (string trim -c ' %' "$_flag_f")
if not test $fuzz -ge 0; or not test $fuzz -le 100
echo "$script: --fuzz must be a number within the range 0 to 100." >&2
exit 1
end
end
for file in $argv
mkdir -p /tmp/autocrop/
cp $file /tmp/autocrop/
convert "$file" -fuzz "$fuzz%" -trim "$file"
end