summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2022-10-09 13:52:42 -0400
committerAndrew Cady <d@jerkface.net>2022-10-09 13:53:09 -0400
commit732df37ee383a76a936d7963a5126266bc3d872f (patch)
tree31c9d569f0541a2059e0bfefa6913fa6e2a2dcc7
parent902c96bd0a5ff1e57f3cefc9eff0ab22c37f95ba (diff)
rename marginate -> letterbox
-rwxr-xr-xdot/local/bin/letterbox37
l---------[-rwxr-xr-x]dot/local/bin/marginate38
2 files changed, 38 insertions, 37 deletions
diff --git a/dot/local/bin/letterbox b/dot/local/bin/letterbox
new file mode 100755
index 0000000..b56e795
--- /dev/null
+++ b/dot/local/bin/letterbox
@@ -0,0 +1,37 @@
1#!/bin/sh
2
3ratio_w=533
4ratio_h=300
5
6sentinel=margins
7
8choose_extent()
9{
10 local ratio_w="$1" ratio_h="$2" input="$3"
11
12 identify -format '%w %h\n' "$input" | {
13
14 read w h || return
15
16 w_prime=$((h * ratio_w / ratio_h))
17 if [ "$w_prime" -gt "$w" ]
18 then
19 w=$w_prime
20 else
21 h=$((w * ratio_h / ratio_w))
22 fi
23 echo ${w}x${h}
24 }
25}
26
27for input
28do
29 case "$input" in
30 *.*) output=${input%.*}.$sentinel.${input##*.} ;;
31 *) output=$input.$sentinel.png ;;
32 esac
33 [ -f "$input" ] || continue
34 extent=$(choose_extent $ratio_w $ratio_h "$input") || continue
35
36 convert "$input" -gravity center -extent "$extent" "$output"
37done
diff --git a/dot/local/bin/marginate b/dot/local/bin/marginate
index b56e795..6bf347f 100755..120000
--- a/dot/local/bin/marginate
+++ b/dot/local/bin/marginate
@@ -1,37 +1 @@
1#!/bin/sh letterbox \ No newline at end of file
2
3ratio_w=533
4ratio_h=300
5
6sentinel=margins
7
8choose_extent()
9{
10 local ratio_w="$1" ratio_h="$2" input="$3"
11
12 identify -format '%w %h\n' "$input" | {
13
14 read w h || return
15
16 w_prime=$((h * ratio_w / ratio_h))
17 if [ "$w_prime" -gt "$w" ]
18 then
19 w=$w_prime
20 else
21 h=$((w * ratio_h / ratio_w))
22 fi
23 echo ${w}x${h}
24 }
25}
26
27for input
28do
29 case "$input" in
30 *.*) output=${input%.*}.$sentinel.${input##*.} ;;
31 *) output=$input.$sentinel.png ;;
32 esac
33 [ -f "$input" ] || continue
34 extent=$(choose_extent $ratio_w $ratio_h "$input") || continue
35
36 convert "$input" -gravity center -extent "$extent" "$output"
37done