328 lines · 7.6 KB · executable
#!/usr/bin/env bash

# Image conversion utility supporting multiple formats
# Usage: convert.sh [options] <input> [output]

set -e

# Default values
QUALITY=90
RESIZE=""
FORMAT=""
VERBOSE=false

# Show usage
usage() {
    cat <<'EOF'
Usage: convert.sh [options] <input> [output]

Options:
    -f, --format <format>    Output format (png, jpg, webp, gif, bmp, tiff, avif, heic)
    -q, --quality <1-100>    Quality for lossy formats (default: 85)
    -r, --resize <geometry>  Resize (e.g., 800x600, 50%, 1920x)
    -v, --verbose            Verbose output
    -h, --help               Show this help

Examples:
    convert.sh input.png output.jpg
    convert.sh -f webp -q 90 input.png output.webp
    convert.sh -f jpg -r 1920x input.png output.jpg
    convert.sh -f webp *.png                    # Batch convert
EOF
    exit 0
}

# Check dependencies
check_deps() {
    local has_im=false
    local has_cwebp=false
    local has_dwebp=false