From 7f67c5fd81f0f01c2751afd7992bf3407c56ae3d Mon Sep 17 00:00:00 2001 From: The_miro Date: Fri, 3 Jul 2026 11:33:33 +0200 Subject: [PATCH] add ascii.conf and keybinds.conf for converter options and rebindable keys ascii.conf exposes ascii-image-converter's dimension/complexity/map/ grayscale/negative/flip options (color and braille stay out since they rely on ANSI/multi-byte Unicode that txt2printr.sh's raw print path can't render). keybinds.conf lets exec-cycle.sh's capture/brightness/ exposure/reset keys be rebound instead of hardcoded, matched case-insensitively; the on-screen hint bar renders from the same config so it never drifts out of sync with the actual bindings. --- ascii.conf | 24 ++++++++++++++++++++++++ exec-cycle.sh | 22 +++++++++++++++------- keybinds.conf | 11 +++++++++++ webcam2ascii.sh | 27 +++++++++++++++++++++++---- 4 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 ascii.conf create mode 100644 keybinds.conf diff --git a/ascii.conf b/ascii.conf new file mode 100644 index 0000000..ec183ff --- /dev/null +++ b/ascii.conf @@ -0,0 +1,24 @@ +# ASCII Photobooth ascii-image-converter configuration +# Sourced by webcam2ascii.sh. All values are optional - blank/false means +# "use the converter's default". + +# Output size in characters (leave both blank to size to the terminal) +WIDTH= +HEIGHT= + +# Use a larger character gradient for smoother shading (true/false) +COMPLEX=false + +# Custom character map, darkest to lightest, e.g. " .:-=+*#%@" +# Overrides COMPLEX if set +CHAR_MAP= + +GRAYSCALE=false +NEGATIVE=false +FLIP_X=false +FLIP_Y=false + +# Color and braille output are intentionally not exposed here: both rely on +# ANSI/multi-byte Unicode that a parallel-port needle printer can't render. +# Only add --color/--braille yourself if you don't plan to print via +# txt2printr.sh. diff --git a/exec-cycle.sh b/exec-cycle.sh index b9e8f40..fdc79ec 100755 --- a/exec-cycle.sh +++ b/exec-cycle.sh @@ -4,11 +4,19 @@ trap 'stty sane; clear; exit 0' SIGINT SIGTERM dir="$(dirname "$0")" [ -f "$dir/webcam.conf" ] && source "$dir/webcam.conf" +[ -f "$dir/keybinds.conf" ] && source "$dir/keybinds.conf" BRIGHTNESS="${DEFAULT_BRIGHTNESS:-auto}" EXPOSURE="${DEFAULT_EXPOSURE:-auto}" STEP="${STEP:-5}" +: "${KEY_CAPTURE:=c}" +: "${KEY_BRIGHTNESS_UP:=+}" +: "${KEY_BRIGHTNESS_DOWN:=-}" +: "${KEY_EXPOSURE_UP:=.}" +: "${KEY_EXPOSURE_DOWN:=,}" +: "${KEY_RESET:=r}" + # clamps $1+$2 to 0-100, treating "auto" as a 50 starting point adjust() { local cur=$1 delta=$2 val @@ -25,16 +33,16 @@ while true; do ./webcam2ascii.sh echo echo "brightness: ${BRIGHTNESS} exposure: ${EXPOSURE}" - echo "[+/-] brightness [./,] exposure [r] reset to auto [c] capture [Ctrl+C] quit" + echo "[${KEY_BRIGHTNESS_UP}/${KEY_BRIGHTNESS_DOWN}] brightness [${KEY_EXPOSURE_UP}/${KEY_EXPOSURE_DOWN}] exposure [${KEY_RESET}] reset to auto [${KEY_CAPTURE}] capture [Ctrl+C] quit" if read -n 1 -t 0.05 -s key; then case "$key" in - "+") BRIGHTNESS=$(adjust "$BRIGHTNESS" "$STEP") ;; - "-") BRIGHTNESS=$(adjust "$BRIGHTNESS" "-$STEP") ;; - ".") EXPOSURE=$(adjust "$EXPOSURE" "$STEP") ;; - ",") EXPOSURE=$(adjust "$EXPOSURE" "-$STEP") ;; - r|R) BRIGHTNESS="${DEFAULT_BRIGHTNESS:-auto}"; EXPOSURE="${DEFAULT_EXPOSURE:-auto}" ;; - c|C) + "$KEY_BRIGHTNESS_UP"|"${KEY_BRIGHTNESS_UP^^}") BRIGHTNESS=$(adjust "$BRIGHTNESS" "$STEP") ;; + "$KEY_BRIGHTNESS_DOWN"|"${KEY_BRIGHTNESS_DOWN^^}") BRIGHTNESS=$(adjust "$BRIGHTNESS" "-$STEP") ;; + "$KEY_EXPOSURE_UP"|"${KEY_EXPOSURE_UP^^}") EXPOSURE=$(adjust "$EXPOSURE" "$STEP") ;; + "$KEY_EXPOSURE_DOWN"|"${KEY_EXPOSURE_DOWN^^}") EXPOSURE=$(adjust "$EXPOSURE" "-$STEP") ;; + "$KEY_RESET"|"${KEY_RESET^^}") BRIGHTNESS="${DEFAULT_BRIGHTNESS:-auto}"; EXPOSURE="${DEFAULT_EXPOSURE:-auto}" ;; + "$KEY_CAPTURE"|"${KEY_CAPTURE^^}") timestamp=$(date +%Y%m%d-%H%M%S) cp web-cam-shot.jpg "photo-$timestamp.jpg" cp ascii-img.txt "ascii-img-$timestamp.txt" diff --git a/keybinds.conf b/keybinds.conf new file mode 100644 index 0000000..d9a2388 --- /dev/null +++ b/keybinds.conf @@ -0,0 +1,11 @@ +# ASCII Photobooth keybindings +# Sourced by exec-cycle.sh. Each value must be a single character; +# matching is case-insensitive. Ctrl+C always quits and isn't +# configurable here. + +KEY_CAPTURE=c +KEY_BRIGHTNESS_UP=+ +KEY_BRIGHTNESS_DOWN=- +KEY_EXPOSURE_UP=. +KEY_EXPOSURE_DOWN=, +KEY_RESET=r diff --git a/webcam2ascii.sh b/webcam2ascii.sh index 74ec9ef..24caeb1 100755 --- a/webcam2ascii.sh +++ b/webcam2ascii.sh @@ -1,11 +1,12 @@ #/bin/bash # # Captures a frame and converts it to ascii art. -# Reads defaults from webcam.conf. BRIGHTNESS/EXPOSURE env vars (set by -# exec-cycle.sh's live preview controls) override the config's defaults. +# Reads defaults from webcam.conf and ascii.conf. BRIGHTNESS/EXPOSURE env +# vars (set by exec-cycle.sh's live preview controls) override webcam.conf. dir="$(dirname "$0")" [ -f "$dir/webcam.conf" ] && source "$dir/webcam.conf" +[ -f "$dir/ascii.conf" ] && source "$dir/ascii.conf" : "${RESOLUTION:=640x480}" : "${JPEG_QUALITY:=85}" @@ -13,11 +14,29 @@ dir="$(dirname "$0")" : "${EXPOSURE:=${DEFAULT_EXPOSURE:-auto}}" : "${BRIGHTNESS_CONTROL:=Brightness}" : "${EXPOSURE_CONTROL:=Exposure (Absolute)}" +: "${COMPLEX:=false}" +: "${GRAYSCALE:=false}" +: "${NEGATIVE:=false}" +: "${FLIP_X:=false}" +: "${FLIP_Y:=false}" set_opts=() [ "$BRIGHTNESS" != "auto" ] && set_opts+=(--set "${BRIGHTNESS_CONTROL}=${BRIGHTNESS}%") [ "$EXPOSURE" != "auto" ] && set_opts+=(--set "${EXPOSURE_CONTROL}=${EXPOSURE}%") -fswebcam -q --no-banner -r "$RESOLUTION" --jpeg "$JPEG_QUALITY" "${set_opts[@]}" web-cam-shot.jpg &> /dev/null -ascii-image-converter web-cam-shot.jpg | tee ascii-img.txt +conv_opts=() +[ -n "$WIDTH" ] && conv_opts+=(--width "$WIDTH") +[ -n "$HEIGHT" ] && conv_opts+=(--height "$HEIGHT") +if [ -n "$CHAR_MAP" ]; then + conv_opts+=(--map "$CHAR_MAP") +elif [ "$COMPLEX" = "true" ]; then + conv_opts+=(--complex) +fi +[ "$GRAYSCALE" = "true" ] && conv_opts+=(--grayscale) +[ "$NEGATIVE" = "true" ] && conv_opts+=(--negative) +[ "$FLIP_X" = "true" ] && conv_opts+=(--flipX) +[ "$FLIP_Y" = "true" ] && conv_opts+=(--flipY) + +fswebcam -q --no-banner -r "$RESOLUTION" --jpeg "$JPEG_QUALITY" "${set_opts[@]}" web-cam-shot.jpg &> /dev/null +ascii-image-converter web-cam-shot.jpg "${conv_opts[@]}" | tee ascii-img.txt