From 701d39f7fb787860b79d1ee1f6b1e44217c2788c Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Thu, 7 Jan 2021 17:53:53 -0500 Subject: marginate --- dot/local/bin/marginate | 39 ++++++++++++++++++++++++++++++--------- 1 file 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 @@ #!/bin/sh -margin=100 -aspect_ratio=177 +ratio_w=533 +ratio_h=300 -extent=$((margin * aspect_ratio / 100))%x${margin}% -options="-gravity center -extent $extent" +sentinel=margins + +choose_extent() +{ + local ratio_w="$1" ratio_h="$2" input="$3" + + identify -format '%w %h\n' "$input" | { + + read w h || return + + w_prime=$((h * ratio_w / ratio_h)) + if [ "$w_prime" -gt "$w" ] + then + w=$w_prime + else + h=$((w * ratio_h / ratio_w)) + fi + echo ${w}x${h} + } +} for input do - case "$input" in - *.*) output=${input%.*}.margins.${input##*.} ;; - *) output=$input.margins.png ;; - esac - convert "$input" $options "$output" + case "$input" in + *.*) output=${input%.*}.$sentinel.${input##*.} ;; + *) output=$input.$sentinel.png ;; + esac + [ -f "$input" ] || continue + extent=$(choose_extent $ratio_w $ratio_h "$input") || continue + + convert "$input" -gravity center -extent "$extent" "$output" done -- cgit v1.2.3