I just wrote some zsh/imagemagick to resize files and then pad
them to a specific image file resolution, however the color of
the rectangle, if I set that to "black" (or #000000) the colors
get screwed up.

If I set it to #000001 tho it works, have no idea why.

Here is the source, the line that bugs me is at line 29 in the
source file, or if you prefer, 39 in this mail :)

#! /bin/zsh
#
# this file:
#   https://dataswamp.org/~incal/conf/.zsh/gfx-resize

rs () {
    local src=$1
    local ext=${src:e}
    local nom=${src:r}
    local dst=${nom}-rs.${ext}

    local w=${2:-1080}
    local h=${3:-720}

    local gm=${w}x${h}

    convert -resize $gm $src $dst
    pad-to-size $dst $w $h
}

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
}

-- 
underground experts united
https://dataswamp.org/~incal

Reply via email to