19 lines · 367 B · executable
#!/usr/bin/env bash

if ! command -v cwebp &>/dev/null; then
    printf "'cwebp' not found. Please install WebP and try again.\n\n"
    exit 1
fi

function usage {
    printf "Convert an image to a PNG-style WebP image.\n\n"
    printf "Usage:\n    %s source\n" "$0"
}

if [[ $# -lt 1 || $1 == "-h" ]]; then
    usage
    exit 1
fi

cwebp -z 9 -o "${1%.*}".webp "$1"