๐พ Archived View for bbs.geminispace.org โบ s โบ ascii-art โบ 16294 captured on 2024-05-26 at 15:02:03. Gemini links have been rewritten to link to archived content
โฌ ๏ธ Previous capture (2024-05-10)
โก๏ธ Next capture (2024-06-16)
-=-=-=-=-=-=-
This should be a reply to [this post] by @requiem, but I could not add a long reply with my code contribution. So I made this separate post.
@requiem provided a bash script that wrapped chafa and outputed gemtext. Chafa is a very nice image-to-text conversion tool that everyone in Geminispace should know about.
I decided to change the original script because it was too interactive, imo, and would be better with proper argument handling. It makes processing faster.
If you don't know, by default chafa outputs are very beautifully rendered, but these are not appropriate to Geminispace due to ANSI color codes. As far as I know, Lagrange cannot render ANSI-colored images correctly.
So long as it is understood that these images are meants to be viewed in the terminal, there is no problem. And so I made standard chafa output the default behavior, with the exception of the width, which I set to 80 characters since that is the standard terminal width.
If you prefer @requiem's style, type the following command:
$ ./chafa-script.sh -S requiem
This sets the style to 240 color block illustration.
There are also `ascii-BW` and `ascii-color` styles, and besides these you can change various options which are explained in the help ('-h').
Another issue is that chafa stretches images horizontally by default, due to the width-to-height ratio of ASCII characters. So I added a correction mode that works by default. If you prefer not to use this, you can turn it off. The feature requires imagemagick to be installed.
So that images are always visible on a single screen, I restricted chafa to producing images 40 characters tall.
I added better renaming logic.
To make the script work on your system, type
$ chmod +x ./chafa-script.sh
That will make the script executable.
Here it is.
#!/bin/bash # chafa-script.sh # a wrapper for chafa that outputs gemtext # modified from code supplied by @requiem:bbs.geminispace.org echo current_date=$(date +'%Y-%m-%d') gallery_name=$current_date # ascii-BW style by default color="full" symbols="" fill="" width="80" foreground="" file_extensions="png|jpg|gif|jpeg|tif|tiff" input_folder="." # Checks if imagemagick/convert is installed, and sets the correction_mode appropriately hash convert &>/dev/null && correction_mode="on" || { correction_mode="off"; \ echo "WARNING: Correction-mode off: $(basename $0) will not correct chafa horizontal stretching"; \ echo " To improve processing, please install imagemagick"; } usage () { echo "$(basename $0): [-i <input-folder>] [-S <style>] [-c <color-#>] [-s <symbols>] [-f <fill-symbols>] [-B background-on-flag] [-w <char-width>] [-d <output-dir>] [-x <file-extensions>] [-r rename-images-to-dir-name] [-R <new-image-name>] [-T thumbnail-mode] [-C correction-mode-off]" echo " style (sets various output options): chafa (default behavior), requiem, ascii-BW, ascii-color" echo " Use this to set all the image settings at once" echo " colors: none, 2, 8, 16, 240, 256, full" echo " symbols: all, ascii, braille, space" echo " fill: all, ascii, none" echo " default width: 80 characters" echo " default output-dir: current date" echo " default file-extensions: 'png|jpg|gif|jpeg|tif|tiff'" echo " thumbnail-mode: width=40" echo " correction-mode-off: by default this script corrects chafa horizontal image stretching;" echo " This option turns off this behavior" echo " rename modes:" echo " -r rename with <output-dir>" echo " -R rename with <new-image-name>" echo "" } while getopts 'hi:S:c:s:f:Bw:d:x:TCrR:' OPTION; do case "$OPTION" in h) usage exit 0 ;; i) input_folder="$OPTARG" ;; S) style="$OPTARG" ;; c) color="$OPTARG" ;; s) symbols="--symbols=$OPTARG" ;; f) fill="--fill=$OPTARG" ;; B) foreground="" ;; w) width="$OPTARG" ;; d) gallery_name="$OPTARG" ;; x) file_extensions="$OPTARG" ;; r) rename_name="_xXx_TBD_xXx_" ;; R) rename_name="$OPTARG" ;; T) width="40" ;; C) echo "INFO: Correction mode turned off" correction_mode="off" ;; *) echo "*** Error: Something went wrong" usage exit 1 ;; esac done # [[ ! $? -eq 0 ]] && { echo "### ERROR: Something went wrong"; exit 1; } # Have to rename this here in case renaming from <output-dir> # Argument parsing might be out of order ('-r' before '-d') if [[ "$rename_name" == "_xXx_TBD_xXx_" ]]; then rename_name=${gallery_name//\//-} # replace '/' with '-' in case dirname is/a/compex/path fi case $style in chafa) chafa_settings="-s ${width}x40" ;; requiem) chafa_settings="-c 240 --color-space din99d --dither ordered --symbols -space -s ${width}x40 --fg-only" ;; ascii-BW) chafa_settings="-c none --color-space din99d --dither ordered --symbols=ascii -s ${width}x40 --fg-only" ;; ascii-color) chafa_settings="-c full --color-space din99d --dither ordered --symbols=ascii --fill=ascii -s ${width}x40 --fg-only" ;; esac [[ -z $chafa_settings ]] && chafa_settings="-c $color --color-space din99d --dither ordered $symbols $fill -s ${width}x40 $foreground" file_extensions="${file_extensions//,/|}" # convert any ',' to '|' file_extensions="${file_extensions// /}" # remove spaces files=$(find $input_folder -maxdepth 1 -type f | grep -iE "$file_extensions") output_dir="$gallery_name" [[ ! -d "${output_dir}" ]] && mkdir -p "$output_dir" # Create index.gmi and add header index_file="$output_dir/index.gmi" echo -e "# Gallery: $gallery_name\n" > "$index_file" # Iterate through each file matching the specified types count=1 for file in $files; do echo "Processing $file" filename=$(basename "$file") if [[ ! -z ${rename_name+x} ]]; then output_filename="${rename_name}-${count}.gmi" else output_filename="${filename%.*}.gmi" fi # Generate individual .gmi files if [ $correction_mode == "on" ]; then convert -resize %100x85% "$file" "${file}.tmp" &>/dev/null # if the conversion succeeds, process the temp file # otherwise process the original file if [[ $? ]]; then { printf '```\r\n'; chafa $chafa_settings "${file}.tmp"; printf '\r\n```'; } > "$output_dir/$output_filename" else echo "WARNING: Problem converting ${filename}; processing original" { printf '```\r\n'; chafa $chafa_settings "$file"; printf '\r\n```'; } > "$output_dir/$output_filename" fi rm "${file}.tmp" &>/dev/null else { printf '```\r\n'; chafa $chafa_settings "$file"; printf '\r\n```'; } > "$output_dir/$output_filename" fi # Generate gallery entry encoded_gmi_filename=$(printf '%s' "$output_filename" | LC_CTYPE=C LANG=C sed -E 's/([^a-zA-Z0-9._~-])/\\%\1/g') filesize=$(du -k "$file" | awk '{print $1}') # Replaced this ๐ป with [IMG] for universal compatability echo "=> $filename [IMG] $encoded_gmi_filename ($filesize kbytes)" >> "$index_file" ((count++)) done # Add file count and creation date to index.gmi echo -e "\n$(($count - 1)) files; created on $current_date." >> "$index_file" echo
Apr 22 ยท 5 weeks ago ยท ๐ mozz, sugar, requiem
๐ requiem ยท Apr 22 at 10:31:
Thank you for making these changes! Proper argument handling and stuff was on my todo list, but I thought for a quick tool this will do! Thank you so much for making the changes.
๐น๏ธ skyjake [...] ยท Apr 23 at 04:12:
I could not add a long reply
You can do this via the draft composer. Start commenting as usual but then just type a backslash:
\
This will create a draft comment where you can enter your long reply just like when making a draft post.
๐ blah_blah_blah [OP] ยท Apr 27 at 15:54:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๏ฟฝ๏ฟฝโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
It works!