diff options
author | Andrew Cady <d@jerkface.net> | 2021-01-07 17:53:53 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2021-01-07 17:53:53 -0500 |
commit | 701d39f7fb787860b79d1ee1f6b1e44217c2788c (patch) | |
tree | fca6a19b4fdf531568df51278eef606ab422cbfd | |
parent | 927b6b752f4f2dff68eb9671eab16797d3be20eb (diff) |
marginate
-rwxr-xr-x | dot/local/bin/marginate | 39 |
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 | ||
3 | margin=100 | 3 | ratio_w=533 |
4 | aspect_ratio=177 | 4 | ratio_h=300 |
5 | 5 | ||
6 | extent=$((margin * aspect_ratio / 100))%x${margin}% | 6 | sentinel=margins |
7 | options="-gravity center -extent $extent" | 7 | |
8 | choose_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 | ||
9 | for input | 27 | for input |
10 | do | 28 | do |
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" | ||
16 | done | 37 | done |