Advertisement
howtophil

fromgreytext.sh

Feb 20th, 2024 (edited)
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.88 KB | None | 0 0
  1. #!/bin/bash
  2. #------------------------------------------------
  3. # A way to send images over thin text-based
  4. # mediums.
  5. #
  6. # This one is "fromgreytext.sh"
  7. # get "togreytext.sh" here: https://pastebin.com/XLFaVVdB
  8. #
  9. # Following the concept of SSTV (Slow Scan TV),
  10. # that images do not need to be perfect or large
  11. # when transmitted over thin mediums, I have made
  12. # This pair of scripts.
  13. #
  14. # The first one, "togreytext.sh" converts an image
  15. # into a small 26-grays grayscale image composed
  16. # of a substitution of letters for numbers in a PGM
  17. # uncompressed image file.
  18. #
  19. # ./togreytext.sh "infile.jpg" 128
  20. #
  21. # This "compressed" PGM can then be sent over LoRa
  22. # or text transmission methods.
  23. #
  24. # Once on the other side, "fromgreytext.sh" can
  25. # be run on the resulting file. It will expand
  26. # the letter back into numbers and set the
  27. # header correctly again.
  28. #
  29. # ./fromgreytext.sh captured.txt>outfile.pgm
  30. #
  31. # That file is then a valid uncompressed PGM
  32. # though grayscale and smaller than the original.
  33. # That PGM can then be converted to your image
  34. # format of choice.
  35. #
  36. # ~HowToPhil 2024/02/21 00:04 EST
  37. #------------------------------------------------
  38.  
  39. # Put the args in pretty vars
  40. FILE="$1"
  41.  
  42. # Expand the header into a proper line-returned pgm header
  43. head -n 1 "$FILE" |tr [:space:] "\n"; echo
  44.  
  45. # Expand the letters into their "clamped" grayscale values
  46. cat "$FILE"|tail -n +1|sed 's/./& /g'\
  47. |sed "s/A/0/g"\
  48. |sed "s/B/10/g"\
  49. |sed "s/C/20/g"\
  50. |sed "s/D/30/g"\
  51. |sed "s/E/40/g"\
  52. |sed "s/F/50/g"\
  53. |sed "s/G/60/g"\
  54. |sed "s/H/70/g"\
  55. |sed "s/I/80/g"\
  56. |sed "s/J/90/g"\
  57. |sed "s/K/100/g"\
  58. |sed "s/L/110/g"\
  59. |sed "s/M/120/g"\
  60. |sed "s/N/130/g"\
  61. |sed "s/O/140/g"\
  62. |sed "s/P/150/g"\
  63. |sed "s/Q/160/g"\
  64. |sed "s/R/170/g"\
  65. |sed "s/S/180/g"\
  66. |sed "s/T/190/g"\
  67. |sed "s/U/200/g"\
  68. |sed "s/V/210/g"\
  69. |sed "s/W/220/g"\
  70. |sed "s/X/230/g"\
  71. |sed "s/Y/240/g"\
  72. |sed "s/Z/255/g"
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement