From 732df37ee383a76a936d7963a5126266bc3d872f Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sun, 9 Oct 2022 13:52:42 -0400 Subject: rename marginate -> letterbox --- dot/local/bin/letterbox | 37 +++++++++++++++++++++++++++++++++++++ dot/local/bin/marginate | 38 +------------------------------------- 2 files changed, 38 insertions(+), 37 deletions(-) create mode 100755 dot/local/bin/letterbox mode change 100755 => 120000 dot/local/bin/marginate 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 @@ +#!/bin/sh + +ratio_w=533 +ratio_h=300 + +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%.*}.$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 diff --git a/dot/local/bin/marginate b/dot/local/bin/marginate deleted file mode 100755 index b56e795..0000000 --- a/dot/local/bin/marginate +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh - -ratio_w=533 -ratio_h=300 - -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%.*}.$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 diff --git a/dot/local/bin/marginate b/dot/local/bin/marginate new file mode 120000 index 0000000..6bf347f --- /dev/null +++ b/dot/local/bin/marginate @@ -0,0 +1 @@ +letterbox \ No newline at end of file -- cgit v1.2.3