#! /bin/zsh # # this file: # https://dataswamp.org/~incal/conf/.zsh/gfx-resize upscale () { local src=$1 local dst=${src:r}-4k.${src:e} local w=2048 local h=$w convert \ $src \ -alpha on \ -virtual-pixel transparent \ -filter Triangle \ +distort Affine "0,0 0,0 %w,0 ${w},0 0,%h 0,${h}" \ -alpha off \ -crop ${w}x${h}+0+0 \ $dst } rs () { local fs=($@) local w=1080 local h=720 local gm=${w}x${h} for src in $fs; do local ext=${src:e} local nom=${src:r} local dst=${nom}-rs.${ext} convert -resize $gm $src $dst pad-to-size $dst $w $h done } pad-to-size () { local src=$1 local nom=${src:r} local ext=${src:e} local w=$2 local h=$3 local col=${4:-#000001} local rect=rect.${ext} draw-rect $w $h $col $rect composite -gravity center $src $rect ${nom}-pad.${ext} rm $rect } draw-rect () { local w=$1 local h=$2 local dim=${w}x${h} local col=${3:-black} local dst=${4:-${col}-${dim}.jpg} convert \ -draw "rectangle 0,0,${w},${h}" \ -fill $col \ -size $dim \ xc:none \ $dst }