togreytext.sh
howtophil |
PRO |
02/21/24 05:24:05 AM UTC (Edited) |
0 ⭐ |
1517 👁️ |
Never ⏰ |
[ascii, text, image, PGM, compress, bbs, meshtastic]
#!/bin/bash #------------------------------------------------ # A way to send images over thin text-based # mediums. # # This one is "togreytext.sh" # get "fromgreytext.sh" here: https://pastebin.com/eSGZ8ZVD # # Following the concept of SSTV (Slow Scan TV), # that images do not need to be perfect or large # when transmitted over thin mediums, I have made # This pair of scripts. # # The first one, "togreytext.sh" converts an image # into a small 26-grays grayscale image composed # of a substitution of letters for numbers in a PGM # uncompressed image file. # # ./togreyutext.sh "infile.jpg" 128 # # This "compressed" PGM can then be sent over LoRa # or text transmission methods. # # Once on the other side, "fromgreytext.sh" can # be run on the resulting file. It will expand # the letter back into numbers and set the # header correctly again. # # ./fromgreytext.sh captured.txt>outfile.pgm # # That file is then a valid uncompressed PGM # though grayscale and smaller than the original. # That PGM can then be converted to your image # format of choice. # # ~HowToPhil 2024/02/21 00:04 EST #------------------------------------------------ # Put the args into pretty vars FILE="$1" #The image file to convert for transmission SQUARE="$2" #The squared geometry of the sent image #Preserve the pgm header but convert the line-returns to spaces for compactness convert "$FILE" -scale $SQUAREx$SQUARE -compress none pgm: |head -n3| tr "\n" " "|sed 's/^[ \t]*//;s/[ \t]*$//';echo # Convert the image to a scaled-down version. # Make the image greyscale. # This will be in uncompressed PGM format. # Clamp grey values into 26 groups which will # be represented by upper-case letters. # Also remove all the spaces after the number-to-letters # but is done. # This essentially compresses and compacts the image # for transmission as text. convert "$FILE" -scale $SQUAREx$SQUARE -compress none pgm: |sed -e 1,3d\ |sed "s/\b[0-9]\b/A/g" \ |sed "s/\b1[0-9]\b/B/g"\ |sed "s/\b2[0-9]\b/C/g"\ |sed "s/\b3[0-9]\b/D/g"\ |sed "s/\b4[0-9]\b/E/g"\ |sed "s/\b5[0-9]\b/F/g"\ |sed "s/\b6[0-9]\b/G/g"\ |sed "s/\b7[0-9]\b/H/g"\ |sed "s/\b8[0-9]\b/I/g"\ |sed "s/\b9[0-9]\b/J/g"\ |sed "s/\b10[0-9]\b/K/g"\ |sed "s/\b11[0-9]\b/L/g"\ |sed "s/\b12[0-9]\b/M/g"\ |sed "s/\b13[0-9]\b/N/g"\ |sed "s/\b14[0-9]\b/O/g"\ |sed "s/\b15[0-9]\b/P/g"\ |sed "s/\b16[0-9]\b/Q/g"\ |sed "s/\b17[0-9]\b/R/g"\ |sed "s/\b18[0-9]\b/S/g"\ |sed "s/\b19[0-9]\b/T/g"\ |sed "s/\b20[0-9]\b/U/g"\ |sed "s/\b21[0-9]\b/V/g"\ |sed "s/\b22[0-9]\b/W/g"\ |sed "s/\b23[0-9]\b/X/g"\ |sed "s/\b24[0-9]\b/Y/g"\ |sed "s/\b25[0-9]\b/Z/g"\ |sed 's/[[:space:]]//g'
Comments
0 B
|0 👍
/0 👎