summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2021-01-07 17:53:53 -0500
committerAndrew Cady <d@jerkface.net>2021-01-07 17:53:53 -0500
commit701d39f7fb787860b79d1ee1f6b1e44217c2788c (patch)
treefca6a19b4fdf531568df51278eef606ab422cbfd
parent927b6b752f4f2dff68eb9671eab16797d3be20eb (diff)
marginate
-rwxr-xr-xdot/local/bin/marginate39
1 files changed, 30 insertions, 9 deletions
diff --git a/dot/local/bin/marginate b/dot/local/bin/marginate
index e62410c..b56e795 100755
--- a/dot/local/bin/marginate
+++ b/dot/local/bin/marginate
@@ -1,16 +1,37 @@
1#!/bin/sh 1#!/bin/sh
2 2
3margin=100 3ratio_w=533
4aspect_ratio=177 4ratio_h=300
5 5
6extent=$((margin * aspect_ratio / 100))%x${margin}% 6sentinel=margins
7options="-gravity center -extent $extent" 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}
8 26
9for input 27for input
10do 28do
11 case "$input" in 29 case "$input" in
12 *.*) output=${input%.*}.margins.${input##*.} ;; 30 *.*) output=${input%.*}.$sentinel.${input##*.} ;;
13 *) output=$input.margins.png ;; 31 *) output=$input.$sentinel.png ;;
14 esac 32 esac
15 convert "$input" $options "$output" 33 [ -f "$input" ] || continue
34 extent=$(choose_extent $ratio_w $ratio_h "$input") || continue
35
36 convert "$input" -gravity center -extent "$extent" "$output"
16done 37done